Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

FREE 12 month online training for ASP.NET & MS Expression Studio and a Free copy of MS Expression Web with Windows Server Purchase
How to get IP Address using VB.Net

Author: Faraz
Download Source Code : 273_SampleProgram.zip

In this sample program I will try to explain you how you can get the IP addresses of your live sites or your local sites. Here I have created a sample program using VS2005.

Some time developing a web application you need to know their IP addresses for hosting etc. Visual Studio.Net and VS 2005 provides a feature for developers to know their websites IP by importing System.Net namespace in your console application. You all have to do is, create a new Console application and add the following code in your project:

 

 

Dim IPHEntry As IPHostEntry

Dim IPAdd() As IPAddress

IPHEntry = Dns.GetHostByName("http://www.devasp.com")

IPAdd = IPHEntry.AddressList

 

Dim i As Integer

For i = 0 To IPAdd.GetUpperBound(0)

      Console.Write("IP Address {0}: {1} ", i, IPAdd(i).ToString)

Next

 

Console.ReadLine()

Notice you can used above code for getting IP information of the live sites to know about the IP address of the local sites in your console application comments the above code and add the following code:

 

Dim localHost As String

localHost = Dns.GetHostName()

IPHEntry = Dns.GetHostByName(localHost)

IPAdd = IPHEntry.AddressList

 

For i = 0 To IPAdd.GetUpperBound(0)

      Console.Write("IP Address {0}: {1} ", i, IPAdd(i).ToString)

Next

 

Console.ReadLine()

Notice code for live site and local site is same the only difference is you passed the live site URL in case of knowing the IP of live site and for local site you will pass localHost name in GetHostByName()method.

Article Comments
I've tried your code and it doesn't return my external IP address but rather the IP address that my router is forwarding requests to. I've been trying for days to find a way to create a VB .NET 2005 application that will update EveryDNS.net with my current dynamic IP Address.

Posted on 7/19/2007 12:38:19 AM by Jeff

I want to get Ipaddresses for every system on lan

Posted on 3/17/2008 2:10:02 AM by Naveed

Dim IPHEntry As IPHostEntry

Dim IPAdd() As IPAddress

IPHEntry = Dns.GetHostByName("http://www.devasp.com")

IPAdd = IPHEntry.AddressList



Dim i As Integer

For i = 0 To IPAdd.GetUpperBound(0)

Console.Write("IP Address {0}: {1} ", i, IPAdd(i).ToString)

Next



Console.ReadLine()

Notice you can used above code for getting IP information of the live sites to know about the IP address of the local sites in your console application comments the above code and add the following code:



Dim localHost As String

localHost = Dns.GetHostName()

IPHEntry = Dns.GetHostByName(localHost)

IPAdd = IPHEntry.AddressList



For i = 0 To IPAdd.GetUpperBound(0)

Console.Write("IP Address {0}: {1} ", i, IPAdd(i).ToString)

Next



Console.ReadLine()

Posted on 5/25/2008 1:11:46 PM by Deepak

I need to get the local IP address. Could you help me

Posted on 11/6/2008 8:17:04 AM by Fatmir

I Want to Local IpAddresses

I am using above code but its not coming there

pls help me

Thanks you Advance

by
srinivas

Posted on 2/2/2009 2:18:07 PM by srinivas

i want to local system ipaddress codding

Posted on 10/1/2009 7:57:31 AM by Jayanta Joarder

for the local ip address of the computer i use:

Dns.GetHostName

instead of localhost or a url

Posted on 12/29/2009 12:22:48 PM by Tom

i want to change the default gateway address of the client using server

Posted on 2/18/2010 5:43:58 AM by arul prasath

Dim ipE As IPHostEntry = Dns.GetHostByName(sHostName)
this line comes into the problem please help me

Posted on 3/3/2010 11:37:21 PM by karthick

i want to know the ip adress of client that attack my pc

Posted on 3/30/2010 9:51:51 PM by sya

i want to determine the IP address of my system network and want to configure it on ma own through some coding.how may i do that?

Posted on 4/18/2010 6:32:39 AM by sadaf

IPHEntry = Dns.GetHostByName("http://www.devasp.com")

i got the error from this line...pls help me.....
error is:DNS is not declared....

Posted on 6/6/2010 12:58:49 AM by bharath

use this it will have a little green thing under Dns.GetHostByName(localHost) but ignore it now you should get ip address of you computer


Imports System.Net

Module Module1

Sub Main()
Dim IPHEntry As IPHostEntry
Dim IPAdd() As IPAddress
Dim localHost As String
localHost = Dns.GetHostName()
IPHEntry = Dns.GetHostByName(localHost)
IPAdd = IPHEntry.AddressList


For i = 0 To IPAdd.GetUpperBound(0)
Console.Write("IP Address {0}: {1} ", i, IPAdd(i).ToString)
Next


Console.ReadLine()

End Sub

End Module

Posted on 8/25/2010 9:35:13 PM by daneleo

I Want to Local IpAddresses

I am using above code but its not coming there

pls help me

Thanks you Advance

by
Neeraj

Posted on 8/28/2010 4:15:33 AM by Neeraj

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< Threading using VB.Net 2005

Disclaimer - Privacy
© 2002-2014 DevASP.net