Advertisement
ตัวอย่างโค้ดโปรแกรม ที่ใช้ในสำหรับการตรวจสอบหมายเลขไอพี (ip) ของเครื่อง ซึ่งในปัจจุบันนี้ หมายเลขไอพีนั้นมีทั้ง ipv4 และ ipv6
Advertisement
using System;
using System.Net;
namespace CheckIP
{
class Program
{
static void Main(string[] args)
{
IPHostEntry host;
host = Dns.GetHostEntry(Dns.GetHostName());
string getIP = "";
Console.WriteLine();
foreach (IPAddress ip in host.AddressList)
{
Console.WriteLine(ip.AddressFamily+" ==> "+ip.ToString()+"\n");
if (ip.AddressFamily.ToString() == "InterNetwork")
{
getIP = ip.ToString();
}
}
Console.WriteLine("-----------------------------------------");
Console.WriteLine("Ip Address IPV4 Is : "+getIP);
Console.WriteLine("-----------------------------------------");
Console.WriteLine();
Console.WriteLine("Powered by dekdev.com");
Console.Read();
}
}
}

Advertisement