NewsFeed   -
KỸ THUẬT LẬP TRÌNH
S  M  L
To get IP Address - C#
You must first import/using System.Net

//To get a host with a www address
IPHostEntry ip = Dns.GetHostByName ("www.vbcity.com");
IPAddress [] IpA = ipE.AddressList;
for (int i = 0; i < IpA.Length; i++)
{
    Console.WriteLine ("IP Address {0}: {1} ", i, IpA[i].ToString ());
}

//To get the local IP address
string sHostName = Dns.GetHostName ();
IPHostEntry ipE = Dns.GetHostByName (sHostName);
IPAddress [] IpA = ipE.AddressList;
for (int i = 0; i < IpA.Length; i++)
{
    Console.WriteLine ("IP Address {0}: {1} ", i, IpA[i].ToString ());
}


---- VB
'To get a www address
Dim i As Integer
Dim ipE As IPHostEntry = Dns.GetHostByName("www.vbcity.com")
Dim IpA() As IPAddress = ipE.AddressList
For i = 0 To IpA.GetUpperBound(0)
    Console.Write("IP Address {0}: {1} ", i, IpA(i).ToString)
Next

'To get local address
Dim sHostName As String
Dim i As Integer
sHostName = Dns.GetHostName()
Dim ipE As IPHostEntry = Dns.GetHostByName(sHostName)
Dim IpA() As IPAddress = ipE.AddressList
For i = 0 To IpA.GetUpperBound(0)
    Console.Write("IP Address {0}: {1} ", i, IpA(i).ToString)
Next

You can use Dns.GetHostAddresses directly - fewer lines fewer bug possibilities. Good tip anyway solved a lot for me as I'm new to .NET TCP/IP. Thanks!
MAC-address follows:
Dim sMac As String
Dim Ni As NetworkInterface()
Ni = NetworkInterface.GetAllNetworkInterfaces ' get info
sMac = Ni(0).GetPhysicalAddress.ToString ' happend to be WLAN, 1 was LAN
sMac += Ni(0).Description.ToString() ' add node description
Debug.Print(sMac) ' - to sort out which node
- 05/20/2011
Search:
NGHỆ THUẬT - PHIM - ẢNH

HÌNH ẢNH ĐẸP

Photo

Album: Royal Wedding
< July 2011 >
Sun Mon Tue Wed Thu Fri Sat
26 27 28 29 30 1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31 1 2 3 4 5 6
More... (All Collections)
H2O NEWS

Everything Meaning To You!

Email: [email protected]

Website: emty.org

Liên hệ

Đặt làm trang chủ

@