Question Find names on devices in a network

_powerade_

Member
Joined
Sep 23, 2008
Messages
19
Programming Experience
5-10
Hi,

I'm currently working on an application that first pings and then, if something "pings back", checks the ip-address using the GetHostEntry statement. If a device is connected at ex. IP 192.168.1.50, it pops up on a list.

But I was wondering... Is it possible to get the name of that device? GetHostEntry only gives me the IP-address (unless its a computer, then the computer name pops up) if it find a router, modem, a mobile device etc...

For example: I have a dreambox connected on my network. Is there a way to get the name of the dreambox when i know its ip??? Or my Nokia? Or my wireless printer???

I'm uploading a picture of the application so you might better understand what i mean.

PS: The text in the application is in Norwegian...
 

Attachments

  • pinger, eksempel.jpg
    pinger, eksempel.jpg
    57 KB · Views: 70
There could possibly be other ways and information when DNS host name is not available, but these could also mean more device specific interfacing. One global option is to get the MAC address, the first 3 bytes of these 6 is something called OUI (Organizationally Unique Identifier) and there exist a public list where you can at least find out which manufacturer produced the NIC, the other 3 bytes probably only each manufacturer know what means. Here is an example I have tested and which worked, you need this declaration:
Private Declare Function SendARP Lib "iphlpapi.dll" (ByVal DestIP As Integer, ByVal SrcIP As Integer, ByRef pMacAddr As Long, ByRef PhyAddrLen As Integer) As Integer
The OUI list can be downloaded from IEEE.org.

Sample code to get MAC and OUI:
VB.NET:
Dim ip As Integer = CInt(Net.IPAddress.Parse("192.123.45.67").Address)
Dim mem As Long
Dim ret As Integer = SendARP(ip, 0, mem, 6)
Dim ab() As Byte = BitConverter.GetBytes(mem)
Dim OUI As String = BitConverter.ToString(ab, 0, 3)
Nevermind the Address obsolete warning, also Vista runs IP4 compatibility translation.

With the OUI string you can search the text file or create yourself a smaller lookup table from it. When successful it is for example more useful to know this manufacturer name "CANON INC." than only the IP.
 
Thanks a lot JohnH :)

This solved the problem.
 
Re: Almost same problem

i have a question which may lead to another question, but here's the first...
how can i get the name of the computer/machine using IP address

ex.
the computer's name is alien with ip address 192.168.0.10
now i have a program which pings the network

Try
Dim IncreaseValue As Integer = 1
Dim Ping As New Ping
Dim PingOptions As New PingOptions
PingOptions.Ttl = 64
Dim PingRep As PingReply

While (IncreaseValue <= 256)
Dim IPAddPC = IpAddressPopulate & IncreaseValue.ToString

PingRep = Ping.Send(IPAddPC, 10)
TextBox1.AppendText(PingRep.Status.ToString & " - " & IPAddPC & vbCrLf)
If PingRep.Status = IPStatus.Success Then
ListBox1.Items.Add(IpAddressPopulate & IncreaseValue) ' & " - Computer responded.")
Else
ListBox1.Items.Add(IpAddressPopulate & IncreaseValue) '& " - Computer did not respond.")
End If
IncreaseValue += 1
End While
Catch ex As Exception

End Try

I have another listbox which lists all the ip address that respond to ping.
My problem now is how to retrieve the name of the computers/machines using that IP address. I did use the System.Net.Dns.GetHostEntry(listbox1.selecteditem.tostring).HostName but it returns the value of the ip address and not the name of the computer...

inside the network we also have some network printers that i must also get the information...

kindly help pls...
 
follow-up:
i use this to get the information using the IP address

Dim co As New ConnectionOptions()
Dim ms As New System.Management.ManagementScope("\\" & Name & "\root\cimv2", co)
Dim oqProcessor = New System.Management.ObjectQuery("SELECT * FROM Win32_Processor")
Dim queryProcessor = New ManagementObjectSearcher(ms, oqProcessor)
Dim queryCollectionProcessor = queryProcessor.[Get]()

using the above code, i could get the information of the computers, however, i could not get the names of the machines(printer, access point)
 
i also tried the Win32_NetworkAdapter (just a little thought: i thought all machines have this property :D) but to no avail...
 
another follow-up, i hope this will be the last follow-up...

another thing inside our network, we have computers that have different operating system... for sure i could ping them but how can i get them name and information...???

i'm very sorry for the readers here, im just a newbie so please bear with me...
 
Hi, try this:

VB.NET:
Imports System.Net

VB.NET:
Dim hostNameOrAddress As String = YourIPadress
Dim returnValue As IPHostEntry

Try
   returnValue = Dns.GetHostEntry(hostNameOrAddress)

   MessageBox.Show(returnValue.HostName())

Catch ex As Exception
   MessageBox.Show(ex.Message)

End Try
 
Last edited:
Hi, try this:

VB.NET:
Imports System.Net

VB.NET:
Dim hostNameOrAddress As String = YourIPadress
Dim returnValue As IPHostEntry

Try
   returnValue = Dns.GetHostEntry(hostNameOrAddress)

   MessageBox.Show(returnValue.HostName())

Catch ex As Exception
   MessageBox.Show(ex.Message)

End Try



thanks for your reply. unfortunately, when i tried this code that you had given, it only returns the given ip address. what i needed is that, if that ip address was assigned to a, for example, a network printer or a router, it will display, either the name of the router or some kind of description.

thanks anyway for the reply. it will be of useful future reference.
 
alienation, did you read post 2 before posting in this thread?
 
yes sir, Mr. JohnH, i have read the 2nd post. i have tried to catch the MAC Address and then compare that to the list you had provided. and it is very useful. however, i also realized that using the table you had given, i could only show 'given' values as to the information of my device, and not the information that was 'assigned' to the device by the administrator.

e.g.
-for router
is it acting as Bridge / Router / Access Point?
version?
updates?
-for printers
info about ink/queue/others which would be helpful in dealing with problems that will arise in the future

i hope you understand what information i want to extract. and don't you worry, i will not use this in hacking or other related stuff, i just needed this for information/inventory gathering information around our own premise only.
 
Back
Top