Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IP address

Status
Not open for further replies.

xeroq

Programmer
Aug 6, 2002
1
AU
Hi all, How can i get the current IP address of a local machine? And when it connect to internet, how can i get both the local LAN ip and internet ip(dynamically assigned)?
Thx
 
Try something like this:

Add the System.Net namespace to your file, then:
Call DNS.GetHostName
- To get the local machine's TCP/IP hostname

Call IPHostEntry.AddressList(machine name)
- To get an array of IPAddress objects for the local machine. Remember that a machine can have more than one card, and possibly several virtual addresses

For each IPAddress object in the array (use a foreach() on it):
if (!ia.IsLoopback()) {
// Is a real IP address
}

Hope this gets you started.

Chip H.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top