|
-
Apr 7th, 2006, 11:01 AM
#1
Thread Starter
Lively Member
[2005] MAC Address -> IP Address
Is it possible to get an IP Address from just a MAC Address? I've found some information on ARP, but it doesn't seem to be what I'm looking for.
Any Ideas?
-
Apr 7th, 2006, 11:08 AM
#2
Re: [2005] MAC Address -> IP Address
MAC addresses are unique in that no other network card on the planet has the same one. IP addresses arent. They can change. So are you just wanting the present IP address that is associated with a particular MAC address?
-
Apr 7th, 2006, 11:13 AM
#3
Thread Starter
Lively Member
Re: [2005] MAC Address -> IP Address
Yes.
We have a bunch of machines on our network and I need to be able to get ahold of that machine again no matter what its IP or Machine Name is. Both the IP and Name change constantly on each machine.
-
Apr 7th, 2006, 11:14 AM
#4
Re: [2005] MAC Address -> IP Address
I'm not so sure if VB can do it
but I know you must send an "ARP request" to retrieve the MAC address
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Apr 7th, 2006, 11:17 AM
#5
Re: [2005] MAC Address -> IP Address
You can do it Good ol' WMI, using the Win32_NetworkAdapterConfiguration WMI class. Below is an example.
VB Code:
**NOTE - add a reference to "System.Management" in your project
Dim MyobjectQuery As New System.Management.ObjectQuery("select * from Win32_NetworkAdapterConfiguration")
Dim MySearcher As New System.Management.ManagementObjectSearcher(MyobjectQuery)
For Each Mgmt As System.Management.ManagementObject In MySearcher.Get()
MessageBox.Show(Mgmt.GetText(TextFormat.Mof))
Next
What this will do is loop through all instances if network adapter configurations, right now it just lists all the properties for all of them. What you would do is look at each one to figure out what properties you want. One of them will have both the IP address and the MAC address of the interface.
-
Apr 7th, 2006, 11:43 AM
#6
Re: [2005] MAC Address -> IP Address
Once thing I noticed is that IP address seems to be an array property... why this is, I do not know, as I dont know how one network interface would have two IP's. You have to cast the property into an array, like the below example. The below example loops through all network interfaces, and displays the Name, Mac address (if there is one), and IP address (if there is one)...
VB Code:
'***NOTE - once again, you need a reference to "System.Management" in order to use
Dim MyobjectQuery As New System.Management.ObjectQuery("select * from Win32_NetworkAdapterConfiguration")
Dim MySearcher As New System.Management.ManagementObjectSearcher(MyobjectQuery)
For Each Mgmt As System.Management.ManagementObject In MySearcher.Get()
'try/catch block needed because not all adapters will return these properties
Try
MessageBox.Show(Mgmt("Caption").ToString)
MessageBox.Show(Mgmt("MACAddress").ToString)
'IP address property seems to be an array, so we have to cast it into one
Dim MyArray As System.Array = DirectCast(Mgmt("IPAddress"), System.Array)
For Each str As String In MyArray
MessageBox.Show(str)
Next
Catch
End Try
Next
Last edited by gigemboy; Apr 7th, 2006 at 11:46 AM.
-
Apr 7th, 2006, 01:58 PM
#7
Thread Starter
Lively Member
Re: [2005] MAC Address -> IP Address
This gets the MAC Address for my local machine right? This code is very interesting, but I need to get the IP of a remote machine by its MAC Address.
-
Apr 7th, 2006, 02:04 PM
#8
Re: [2005] MAC Address -> IP Address
Well there is a way to do it from another machine on the network by supplying a managementscope parameter of the ManagementObjectSearcher object (in codebank submission). If you are referring to machines outside the network, then I dont think this would apply..
-
Apr 7th, 2006, 06:56 PM
#9
Re: [2005] MAC Address -> IP Address
gigemboy, you can have multiple network adapters on 1 computer which is probably why the IP addresses are an array.
-
Apr 7th, 2006, 10:24 PM
#10
Re: [2005] MAC Address -> IP Address
 Originally Posted by kasracer
gigemboy, you can have multiple network adapters on 1 computer which is probably why the IP addresses are an array.
Yeah but it loops for all network interfaces. Each network interface has the property that is an array. You wont have 2 IP's for 1 network interface... as far as I know... unless maybe 1 will return the regular IP and loopback IP?
-
Apr 8th, 2006, 12:23 AM
#11
Re: [2005] MAC Address -> IP Address
 Originally Posted by gigemboy
Yeah but it loops for all network interfaces. Each network interface has the property that is an array. You wont have 2 IP's for 1 network interface... as far as I know... unless maybe 1 will return the regular IP and loopback IP?
The loopback address is implimented in the device's drivers. It shouldn't count that as a second IP.
It's probably related to network cards like this one: http://www.newegg.com/Product/Produc...82E16833106217
-
Apr 9th, 2006, 12:26 PM
#12
Re: [2005] MAC Address -> IP Address
you don't really need to add references to the ManagementObject, you could always use a simple API call ( *** just as an alternative *** )
on your local network you can use the SendARP API, you can also use this for any network interfaces on your own machine.
here's a quick example i bunged together for you , it's based on a few C# examples floating about, i just modified it to work in VB.NET...
VB Code:
[COLOR=Blue]Private Declare[/COLOR] [COLOR=Blue]Function[/COLOR] inet_addr [COLOR=Blue]Lib[/COLOR] "ws2_32.dll" ([COLOR=Blue]ByVal[/COLOR] cp [COLOR=Blue]As String[/COLOR]) [COLOR=Blue]As[/COLOR] Int32
[COLOR=Blue]Private Declare Function[/COLOR] SendARP [COLOR=Blue]Lib[/COLOR] "IPHLPAPI.dll" ([COLOR=Blue]ByVal[/COLOR] DestIP [COLOR=Blue]As Integer[/COLOR], [COLOR=Blue]ByVal[/COLOR] SrcIP [COLOR=Blue]As[/COLOR] Int32, [COLOR=Blue]ByVal[/COLOR] pMacAddr [COLOR=Blue]As Byte[/COLOR](), [COLOR=Blue]ByRef [/COLOR] PhyAddrLen [COLOR=Blue]As[/COLOR] Int32) [COLOR=Blue]As[/COLOR] Int32
[COLOR=Blue]Private Sub[/COLOR] Button1_Click([COLOR=Blue]ByVal[/COLOR] sender [COLOR=Blue]As[/COLOR] System.Object, [COLOR=Blue]ByVal[/COLOR] e [COLOR=Blue]As[/COLOR] System.EventArgs) [COLOR=Blue]Handles[/COLOR] Button1.Click
[COLOR=Green]'/// buffer to receive the MacAddress into...[/COLOR]
[COLOR=Blue]Dim[/COLOR] buf(6) [COLOR=Blue]As Byte[/COLOR]
[COLOR=Green]'/// specify your ip to check here *** remember to add Imports System.NET at the top of the code window *** ...[/COLOR]
[COLOR=Blue]Dim[/COLOR] ip [COLOR=Blue]As[/COLOR] IPAddress = IPAddress.Parse("192.168.0.4")
[COLOR=Blue]If[/COLOR] SendARP(BitConverter.ToInt32(IPAddress.Parse("192.168.0.4").GetAddressBytes, 0), 0, buf, 6) = 0 [COLOR=Blue]Then[/COLOR]
Console.WriteLine(BitConverter.ToString(buf, 0, 6))
[COLOR=Blue]End If[/COLOR]
[COLOR=Blue]End Sub[/COLOR]
~
if a post is resolved, please mark it as [Resolved]
protected string get_Signature(){return Censored;}
[vbcode][php] please use code tags when posting any code [/php][/vbcode]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|