VB.Net : Find all IPs on a LAN

How do i get the IPs of all computers on a network?

Page 1 of 1

8 Replies - 84456 Views - Last Post: 03 August 2012 - 10:05 PM Rate Topic: -----

#1 Mathieu  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 28-February 07

VB.Net : Find all IPs on a LAN

Posted 28 February 2007 - 12:22 PM

Hi,

I've been trying to get the IPs (or computer names) of the computers in the same network as the computer running the program.

I got as far as getting all the IPs of the servers in the network wich ended up in a dead end since its all the computers that i need and not the servers only.

My goal is to get acces to files on all the other computers, i guess a shared folder would do the work and just access it as a regular folder, but for that i need the computer name (wich i can get through his IP)


Basicly, I need to find the ips of all computers in the same network wich is not what i get right now...

		   Dim localIP() As System.Net.IPAddress = System.Net.Dns.GetHostAddresses(System.Net.Dns.GetHostName)
			Dim strLocalIP As String = localIP(0).ToString
			Dim DomainHostEntry As System.Net.IPHostEntry
			DomainHostEntry = System.Net.Dns.GetHostEntry("workgroup")

			DomainAdressList = DomainHostEntry.AddressList



Thanks for the Help

- Mathieu

This post has been edited by Mathieu: 28 February 2007 - 12:35 PM


Is This A Good Question/Topic? 0
  • +

#5 whisla13  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 10
  • Joined: 22-May 07

Re: VB.Net : Find all IPs on a LAN

Posted 22 May 2007 - 11:20 AM

Try obtaining the standard output from executing "net view". This will give you all discovered computer names (in the same workgroup) on the network.

A more advanced way would be to calculate the IP address ranges of the network based on the computer's subnet mask and IP. For example, if the computer's subnet mask is 255.255.255.0, and the computer's IP is 192.168.1.52, you can calculate from the subnet mask that valid IP address ranges on this network is 192.168.1.1 to 192.168.1.254, therefore giving you 254 addresses you can send an ICMP ECHO packet to (ping), and if you get a response packet back, then you have discovered a computer on the network. If using Framework 2.0, you can use My.Computer.Network.Ping.

- Andrew
Was This Post Helpful? 1

#6 matoksoz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 17-June 07

Re: VB.Net : Find all IPs on a LAN

Posted 17 June 2007 - 03:58 PM

here is my c# code

Process netsend = new Process();
netsend.StartInfo.FileName = "net.exe";
netsend.StartInfo.CreateNoWindow = true;
netsend.StartInfo.Arguments = "view";
netsend.StartInfo.RedirectStandardOutput = true;
netsend.StartInfo.UseShellExecute = false;
netsend.StartInfo.RedirectStandardError = true;
netsend.Start();


StreamReader sr = new StreamReader(netsend.StandardOutput.BaseStream, netsend.StandardOutput.CurrentEncoding);

string sss = "";
while ((sss = sr.ReadLine()) != null)
{
if (sss.StartsWith("\\"))
comboBox1.Items.Add(sss.Substring(2).Substring(0, sss.Substring(2).IndexOf(" ")).ToUpper();
}

sr.Close();
netsend.WaitForExit(1000);

string dom = Dns.GetHostName().ToUpper();
dom = dom + "\\SQLEXPRESS";
if (!comboBox1.Items.Contains(dom))
comboBox1.Items.Add(dom);

I hope this helps you
Mehmet Altan Toksöz
Was This Post Helpful? 0
  • +
  • -

#7 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1638
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: VB.Net : Find all IPs on a LAN

Posted 26 July 2007 - 07:24 AM

You can use this function as well.
Make sure to have this at the top of your class
Imports System.Net



Public Shared Function GetAllIP(Optional ByVal args As String() = Nothing) As Integer

		Dim strHostName As New String("")
		If args.Length = 0 Then
			' Getting Ip address of local machine...
			' First get the host name of local machine.
			strHostName = DNS.GetHostName()
			Console.WriteLine("Local Machine's Host Name: " + strHostName)
		Else
			strHostName = args(0)
		End If

		' Then using host name, get the IP address list..
		Dim ipEntry As IPHostEntry = DNS.GetHostByName(strHostName)
		Dim addr As IPAddress() = ipEntry.AddressList

		Dim i As Integer = 0
		While i < addr.Length
			Console.WriteLine("IP Address {0}: {1} ", i, addr(i).ToString())
			System.Math.Max(System.Threading.Interlocked.Increment(i), i - 1)
		End While
		Return 0
	End Function



The args parameter is optional, if you pass it nothing it will retrieve the host name of the comp-uter you're on, then loop and get all IP's for that hostname. You must have a reference to System.Net.DLL in your reference list to make this work.
Was This Post Helpful? 1

#8 motcom  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 290
  • View blog
  • Posts: 1,371
  • Joined: 16-June 08

Re: VB.Net : Find all IPs on a LAN

Posted 03 June 2010 - 08:06 AM

A 3 year old post gets resurrected by "Hi"...
Was This Post Helpful? 0
  • +
  • -

#9 dbasnett  Icon User is offline

  • D.I.C Addict

Reputation: 108
  • View blog
  • Posts: 601
  • Joined: 01-October 08

Re: VB.Net : Find all IPs on a LAN

Posted 03 June 2010 - 12:35 PM

Why?
Was This Post Helpful? 0
  • +
  • -

#10 Guest_jay_s12*


Reputation:

Re: VB.Net : Find all IPs on a LAN

Posted 04 August 2010 - 11:22 PM

All Ip Address List on LAN That are Available.Try this guys,but change the ip in Code as u want.

Dim oWMI = GetObject("winmgmts:")
Dim IP = GetObject("winmgmts:")
Dim oPings = GetObject("winmgmts:")
Dim PcName = GetObject("winmgmts:")


For i = 100 To 101
IP = "192.168.1." + i.ToString
oPings = oWMI.ExecQuery("Select * from WIN32_Pingstatus where address='" + IP + "'" + " and ResponseTime > 0")

For Each oPing In oPings
PcName = System.Net.Dns.GetHostEntry(IP)
txtlistofhost.Text &= IP & Chr(9) & PcName.HostName & vbNewLine
Next

Next
Was This Post Helpful? 0

#11 austincr48  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 31-July 12

Re: VB.Net : Find all IPs on a LAN

Posted 03 August 2012 - 09:16 PM

View PostPsychoCoder, on 26 July 2007 - 07:24 AM, said:

You can use this function as well.
Make sure to have this at the top of your class
Imports System.Net



Public Shared Function GetAllIP(Optional ByVal args As String() = Nothing) As Integer

		Dim strHostName As New String("")
		If args.Length = 0 Then
			' Getting Ip address of local machine...
			' First get the host name of local machine.
			strHostName = DNS.GetHostName()
			Console.WriteLine("Local Machine's Host Name: " + strHostName)
		Else
			strHostName = args(0)
		End If

		' Then using host name, get the IP address list..
		Dim ipEntry As IPHostEntry = DNS.GetHostByName(strHostName)
		Dim addr As IPAddress() = ipEntry.AddressList

		Dim i As Integer = 0
		While i < addr.Length
			Console.WriteLine("IP Address {0}: {1} ", i, addr(i).ToString())
			System.Math.Max(System.Threading.Interlocked.Increment(i), i - 1)
		End While
		Return 0
	End Function



The args parameter is optional, if you pass it nothing it will retrieve the host name of the comp-uter you're on, then loop and get all IP's for that hostname. You must have a reference to System.Net.DLL in your reference list to make this work.


I know that this thread is old but I ran into a problem with the 'solution'. I have a variety of different IP addresses on one machine and for some reason. I am returning all of the IP addresses that the computer has. Is there a method that this actually would work with?
Was This Post Helpful? 0
  • +
  • -

#12 austincr48  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 31-July 12

Re: VB.Net : Find all IPs on a LAN

Posted 03 August 2012 - 10:05 PM

This is the result, also grabbing the ip's hostname at the same time. It seems like if I could narrow it down to a single interface I would be able to get the desired result. Is there a way to select the interface?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1