Google Groepen ondersteunt geen nieuwe Usenet-berichten of -abonnementen meer. Historische content blijft zichtbaar.

See IP address

19 weergaven
Naar het eerste ongelezen bericht

BobAchgill

ongelezen,
6 dec 2007, 12:01:0206-12-2007
aan
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

ongelezen,
6 dec 2007, 12:26:4106-12-2007
aan
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

ongelezen,
6 dec 2007, 13:11:3406-12-2007
aan
"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

ongelezen,
6 dec 2007, 14:36:5806-12-2007
aan
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

ongelezen,
7 dec 2007, 08:27:4307-12-2007
aan
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 nieuwe berichten