Finding IP address

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hi, im making a program that uses the IP address of the computer its on, but
i dont kno how to programmaticly find it.....can anyone point me in the rite
direction? thanks
 
Imports System.Net

Dim HostIP As IPAddress
HostIP = Dns.GetHostByName(Dns.GetHostName).AddressList.GetValue(0)

Rgds, Phil
 
and if the computer is behind a router, is there a way to know the
public(Internet) IP?

thanks
 
Here is the same but in c#

using System.Net;
//
IPHostEntry o = Dns.GetHostByName( Dns.GetHostName() );
MessageBox.Show("Your IP address is : " +o.AddressList[0] );

good luck !

craig kelly-soens - Windows Vista WinFx XAML .Net Evangelist
http://www.XpectWorld.com - customised "super-easy to use" Windows Vista
based software & consultancy
 
Is there a way to programatically get the router IP address, if the LAN is on
a router?
--
Michael Bragg, President
eSolTec, Inc.
a 501(C)(3) organization
MS Authorized MAR
looking for used laptops for developmentally disabled.
 
You could get it from WMI.

WIN32_NetworkAdapterConfiguration.DefaultIpGateway


eSolTec said:
Is there a way to programatically get the router IP address, if the LAN is
on
a router?
--
Michael Bragg, President
eSolTec, Inc.
a 501(C)(3) organization
MS Authorized MAR
looking for used laptops for developmentally disabled.
 
Hi

I agree Terry's suggestion, here I provide the code snippet for your
reference.

'NOTE: You need add reference to System.Management.dll first.
Dim mc As System.Management.ManagementClass
Dim mo As ManagementObject
mc = New ManagementClass("Win32_NetworkAdapterConfiguration")
Dim moc As ManagementObjectCollection = mc.GetInstances()
For Each mo In moc
If mo.Item("IPEnabled") = True Then
Debug.WriteLine("Network Adapter MAC address " &
mo.Item("MacAddress").ToString())
Debug.WriteLine("Gateway(Rounter): ")
Dim ss() As String = mo.Item("DefaultIpGateway")
For Each s As String In ss
Debug.WriteLine(" " + s)
Next
End If
Next

You may have a try, and if you have other concern, please feel free to let
me know.

Best regards,

Peter Huang

Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Peter,

Thank you for your code snippet. It is greatly appreciated. Now I'm
wondering how to get the information from the Immediate window into a label
container :) please
--
Michael Bragg, President
eSolTec, Inc.
a 501(C)(3) organization
MS Authorized MAR
looking for used laptops for developmentally disabled.
 
Hi Michael,

For the other Debug.Print, it is simple.
Change the Debug.WriteLine to LabelX.Text =

For the code below.
For Each s As String In ss
Debug.WriteLine(" " + s)
Next

We need to decided how many labels or which element we want in the ss
string array.
e.g.
If ss.Length > 1 Then
Label1.Text = ss(0)
End If

You may have a try and let me know the result. :)

Best regards,

Peter Huang

Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top