อาจจะยาวหน่อยแต่ก็ช่วยหน่อยนะครับ ถ้าได้แบบทีละบรรทัดจะดีมากเลย ขอบคุณล่วงหน้าครับ
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
using System.Net.NetworkInformation;
using System.Threading;
namespace IP_Information_Checker
{
    public partial class Form1 : Form
    {
        AutoResetEvent resetEvent = new AutoResetEvent(false);
        IPAddress test1 = IPAddress.Parse("192.168.1.1");
        IPAddress test2 = IPAddress.Loopback;
        IPAddress test3 = IPAddress.Broadcast;
        IPAddress test4 = IPAddress.Any;
        IPAddress test5 = IPAddress.None;
        public Form1()
        {
            InitializeComponent();
        }
        private void btnShowIP_Click(object sender, EventArgs e)
        {
            try
            {
                IPHostEntry myHostName = Dns.GetHostByName(Dns.GetHostName());
                IPAddress myself = myHostName.AddressList[0];
                if (IPAddress.IsLoopback(test2))
                    txtIP1.Text = test2.ToString();
                txtIP2.Text = myself.ToString();
                txtIP3.Text = test1.ToString();
                txtIP4.Text = test3.ToString();
                txtIP5.Text = test4.ToString();
                txtIP6.Text = test5.ToString();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Information");
            }
        }
        private void txtShowDNS_Click(object sender, EventArgs e)
        {
            try
            {
                string hostName = Dns.GetHostName();
                txtDNS1.Text = hostName;
                IPHostEntry myself = Dns.GetHostByName(hostName);
                foreach (IPAddress address in myself.AddressList)
                {
                    txtDNS2.Text = address.ToString();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Information");
            }
        }
        private void btnShowIPendPoint_Click(object sender, EventArgs e)
        {
            try
            {
                IPAddress test1 = IPAddress.Parse("192.168.1.1");
                IPEndPoint ie = new IPEndPoint(test1, 8000);
                txtPoint1.Text = ie.ToString();
                txtPoint2.Text = ie.AddressFamily.ToString();
                txtPoint3.Text = ie.Address.ToString();
                txtPoint4.Text = ie.Port.ToString();
                txtPoint5.Text = IPEndPoint.MinPort.ToString();
                txtPoint6.Text = IPEndPoint.MaxPort.ToString();
                ie.Port = 80;
                txtPoint7.Text = ie.ToString();
                SocketAddress sa = ie.Serialize();
                txtPoint8.Text = sa.ToString();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Information");
            }
        }
        private void btnShowSocket_Click(object sender, EventArgs e)
        {
            try
            {
                IPAddress ia = IPAddress.Parse("127.0.0.1");
                IPEndPoint ie = new IPEndPoint(ia, 8000);
                Socket test = new Socket(AddressFamily.InterNetwork,
                       SocketType.Stream, ProtocolType.Tcp);
                txtSocket1.Text = test.AddressFamily.ToString();
                txtSocket2.Text = test.SocketType.ToString();
                txtSocket3.Text = test.ProtocolType.ToString();
                txtSocket4.Text = test.Blocking.ToString();
                test.Blocking = false;
                txtSocket5.Text = test.Blocking.ToString();
                txtSocket6.Text = test.Connected.ToString();
                test.Bind(ie);
                IPEndPoint iep = (IPEndPoint)test.LocalEndPoint;
                txtSocket7.Text = iep.ToString();
                test.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Information");
            }
        }																															
						 
												
						
					
ใครก็ได้ช่วยอธิบาย code visual c# ให้ผมหน่อย จะสอบแล้ว ยังไม่รู้เรื่องอะไรเลย (ช่วยหน่อยนะครับ ขอบคุณครับ)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
using System.Net.NetworkInformation;
using System.Threading;
namespace IP_Information_Checker
{
public partial class Form1 : Form
{
AutoResetEvent resetEvent = new AutoResetEvent(false);
IPAddress test1 = IPAddress.Parse("192.168.1.1");
IPAddress test2 = IPAddress.Loopback;
IPAddress test3 = IPAddress.Broadcast;
IPAddress test4 = IPAddress.Any;
IPAddress test5 = IPAddress.None;
public Form1()
{
InitializeComponent();
}
private void btnShowIP_Click(object sender, EventArgs e)
{
try
{
IPHostEntry myHostName = Dns.GetHostByName(Dns.GetHostName());
IPAddress myself = myHostName.AddressList[0];
if (IPAddress.IsLoopback(test2))
txtIP1.Text = test2.ToString();
txtIP2.Text = myself.ToString();
txtIP3.Text = test1.ToString();
txtIP4.Text = test3.ToString();
txtIP5.Text = test4.ToString();
txtIP6.Text = test5.ToString();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Information");
}
}
private void txtShowDNS_Click(object sender, EventArgs e)
{
try
{
string hostName = Dns.GetHostName();
txtDNS1.Text = hostName;
IPHostEntry myself = Dns.GetHostByName(hostName);
foreach (IPAddress address in myself.AddressList)
{
txtDNS2.Text = address.ToString();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Information");
}
}
private void btnShowIPendPoint_Click(object sender, EventArgs e)
{
try
{
IPAddress test1 = IPAddress.Parse("192.168.1.1");
IPEndPoint ie = new IPEndPoint(test1, 8000);
txtPoint1.Text = ie.ToString();
txtPoint2.Text = ie.AddressFamily.ToString();
txtPoint3.Text = ie.Address.ToString();
txtPoint4.Text = ie.Port.ToString();
txtPoint5.Text = IPEndPoint.MinPort.ToString();
txtPoint6.Text = IPEndPoint.MaxPort.ToString();
ie.Port = 80;
txtPoint7.Text = ie.ToString();
SocketAddress sa = ie.Serialize();
txtPoint8.Text = sa.ToString();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Information");
}
}
private void btnShowSocket_Click(object sender, EventArgs e)
{
try
{
IPAddress ia = IPAddress.Parse("127.0.0.1");
IPEndPoint ie = new IPEndPoint(ia, 8000);
Socket test = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp);
txtSocket1.Text = test.AddressFamily.ToString();
txtSocket2.Text = test.SocketType.ToString();
txtSocket3.Text = test.ProtocolType.ToString();
txtSocket4.Text = test.Blocking.ToString();
test.Blocking = false;
txtSocket5.Text = test.Blocking.ToString();
txtSocket6.Text = test.Connected.ToString();
test.Bind(ie);
IPEndPoint iep = (IPEndPoint)test.LocalEndPoint;
txtSocket7.Text = iep.ToString();
test.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Information");
}
}