Hello, i'm making a small little app that pings all ips on a network from 192.168.0.1 to 192.168.0.255 and populates the active IPs into a listbox. Then from there i want you to be able to select one to look up the machines name on the LAN.

Private Sub Lookup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Lookup.Click
        Dim sel As String
        If ListBox1.Items.Count = 0 Then
            MessageBox.Show("No IP Selection!")

        Else
     'Puts IP into string
            sel = ListBox1.SelectedItem.ToString()
       'SHOULD show the host name but is only one   
  MessageBox.Show(System.Net.Dns.GetHostEntry(sel).HostName)

        End If
    End Sub

But this code doesn't return IP's that are not... me... basically.
It only returns the name of the machine that is searching, not other machines.

Any Help is Greatly appreciated :)

-Zander

Thanks for the reply, but i cant seem to get that to work with my code. i'll continue to tinker with it and see if i get anything.

meanwhile, anyone else?

maybe there is someway to run ipconfig -a in VB?

and CodeFreak, i have tried that, but all it returns is the DNS host name, not the actual machine name, thanks though.

maybe there is someway to run ipconfig -a in VB?

Yes, you could shell (or use a process for) that and pipe the output to a text file. But ipconfig gives you information about local computer's network adapters. You can't get remote computer's name with it.

well I only need names of computers on LAN... and I think there is a command that may get the MAC instead of the machines name... witch would also be fine... the command is like aps /all or something... im gona hit the hay for tonight i'll look into the cmd stuff tomorrow... thanks for the help.

Zander

I managed to get this code, it works but it is slow.

Dim _oWMI, _IP, _oPings,_PcName
_oWMI = GetObject("winmgmts:")
For I = 1 To 255
    _IP = "192.168.0." + 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)
        Debug.Print(_IP & Chr(9) & _PcName.HostName)
    Next
Next I

I was quite sure that WMI has some way to find out remote machine names.

I didn't test the code myself, but would it be faster to ping first the desired IP address space and call _oPings = _oWMI.ExecQuery("Select * from WIN32_Pingstatus where address='" + _IP + "'" + " and ResponseTime > 0") for only those IPs that do response to ping?

Ok, i was able to get the MAC address from ARP -a in a .bat file

Dim oProcess As New Process
                'this is the bat file to run
                Dim s As String = System.AppDomain.CurrentDomain.BaseDirectory + "MAC.bat"
                Dim sOutput As String

                oProcess.StartInfo.FileName = s
                oProcess.StartInfo.UseShellExecute = False
                oProcess.StartInfo.CreateNoWindow = True
                oProcess.StartInfo.RedirectStandardOutput = True
                oProcess.Start()

                Dim sOut As System.IO.StreamReader = oProcess.StandardOutput

                oProcess.WaitForExit(10000) '10 seconds
                'grab the StdOut
                sOutput = sOut.ReadToEnd
                'clean up
                sOut.Close()
                oProcess.Close()
                'display the results
                Form2.TextBox1.Text = sOutput

Thanks for all your help guys!!!

I was quite sure that WMI has some way to find out remote machine names.
for only those IPs that do response to ping?

Actually I don't think so.

The ping itself is slow, I had tried to ping with many ways.
#1

_PingReply = My.Computer.Network.Ping(_IP)

#2

_oPings = _oWMI.ExecQuery("Select * from WIN32_Pingstatus where address='" + _IP + "'")

#3

_oWSH = CreateObject("Wscript.shell")
 _DOS = "cmd /c ping -n 1 -w 1 192.168.0." & I.ToString
_PingReply = _oWSH.Run(_DOS, 0, True)

#4

IF _NetInfoPing.Send("192.168.0." + I.ToString).Status = Net.NetworkInformation.IPStatus.Success Then

The ping should wait and get the response, and that makes it slow to enumerate all the IP address in range (1-255)

I guess I will change the way , I will try to find a way to list all online pc on LAN (workgroup or domain) and then resolve it is name.

I will post back if I got a faster result.

I was quite sure that WMI has some way to find out remote machine names.
for only those IPs that do response to ping?

Actually I don't think so.

The ping itself is slow, I had tried to ping with many ways.
#1

_PingReply = My.Computer.Network.Ping(_IP)

#2

_oPings = _oWMI.ExecQuery("Select * from WIN32_Pingstatus where address='" + _IP + "'")

#3

_oWSH = CreateObject("Wscript.shell")
 _DOS = "cmd /c ping -n 1 -w 1 192.168.0." & I.ToString
_PingReply = _oWSH.Run(_DOS, 0, True)

#4

IF _NetInfoPing.Send("192.168.0." + I.ToString).Status = Net.NetworkInformation.IPStatus.Success Then

The ping should wait and get the response, and that makes it slow to enumerate all the IP address in range (1-255)

I guess I will change the way , I will try to find a way to list all online pc on LAN (workgroup or domain) and then resolve it is name.

I will post back if I got a faster result.

Actually I've never had a need to ping a range addresses, only ping a set of already known IPs. And yes, the pinging is slow if you need to check a range of addresses. It was just my guess that the name solving would be the slow process. But after rethinking it, I concluded that my 'guess' was wrong ;)

_PingReply = My.Computer.Network.Ping(_IP)

should work just fine.
if you want to make the non-used IP's timeout shorter then use

_PingReply = My.Computer.Network.Ping(_IP, <Timeout In Miliseconds)
This question has already been answered. Start a new discussion instead.