Google Ryhmät ei enää tue uusia Usenet-postauksia tai ‐tilauksia. Aiempi sisältö on edelleen nähtävissä.

See IP address

19 katselukertaa
Siirry ensimmäiseen lukemattomaan viestiin

BobAchgill

lukematon,
6.12.2007 klo 12.01.026.12.2007
vastaanottaja
How can I see what the IP address of the computer my code is running on
programmatically?

I have tried something someone gave me but it seems to be obsolete (there is
a wavy blue line under the "myip.Address." ) and returns a number that does
not appear to be a IP address. It does not have periods "." in it.

This is what I am using now.


Thanks!

Bob
-----

Dim myip As Net.IPAddress
myip =
Net.Dns.GetHostByName(Environment.MachineName).AddressList(0)

Dim IPAddress As String

IPAddress = myip.Address.ToString


Jerry Spence1

lukematon,
6.12.2007 klo 12.26.416.12.2007
vastaanottaja
I have the following (as there may be more than one IP address) on VB2005

Dim IP() As String

Dim MyPC As String = Dns.GetHostName

For n As Integer = 0 To
UBound(Dns.GetHostEntry(Dns.GetHostName()).AddressList)

ReDim Preserve IP(n)

IP(n) = Dns.GetHostEntry(MyPC).AddressList(n).ToString

Next

-Jerry

"BobAchgill" <BobAc...@discussions.microsoft.com> wrote in message
news:08B42E2E-F0FB-4BC9...@microsoft.com...

Armin Zingler

lukematon,
6.12.2007 klo 13.11.346.12.2007
vastaanottaja
"BobAchgill" <BobAc...@discussions.microsoft.com> schrieb


As a computer can have multiple network interfaces and multiple IP
addresses, it is not that simple. First, call

System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces

Then, for each returned interface, call the GetIPProperties function which
returns an IPInterfaceProperties object. Among others, this object has a
UnicastAddresses property returning a UnicastIPAddressInformationCollection
object. It's a collection of UnicastIPAddressInformation objects. They have
an Address property. You can call it's ToString function.


...but why so many words? Some code:

Dim NInterfaces As NetworkInterface()

NInterfaces = NetworkInterface.GetAllNetworkInterfaces

For Each NInterface As NetworkInterface In NInterfaces
Debug.Print("Interface: " & NInterface.Description)

For Each Info As IPAddressInformation _
In NInterface.GetIPProperties().UnicastAddresses

Debug.Print(" " & Info.Address.ToString())
Next
Next


Armin


ShaneO

lukematon,
6.12.2007 klo 14.36.586.12.2007
vastaanottaja
BobAchgill wrote:
> How can I see what the IP address of the computer my code is running on
> programmatically?
>
As already mentioned, you need to be aware that there may be more than
one IP address. Therefore, my way is -

Dim NIC_IPs() As IPAddress = Dns.GetHostEntry(Dns.GetHostName()).AddressList

For Each IPAdr As IPAddress In NIC_IPs
Debug.Print(IPAdr.ToString)
Next

(Remember to use 'Imports System.Net')

ShaneO

There are 10 kinds of people - Those who understand Binary and those who
don't.

cj

lukematon,
7.12.2007 klo 8.27.437.12.2007
vastaanottaja
This is what I use.

Dim ipAddressInfo As System.Net.IPHostEntry =
System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName())

Dim ipAddress As String = ipAddressInfo.AddressList.GetValue(0).ToString

Works for me.

0 uutta viestiä