Getting MAC address from IP Address

  • Thread starter Thread starter Jean-Michel Cafagna
  • Start date Start date
J

Jean-Michel Cafagna

Hi all,

I have a question for you,

I'm looking for a way to have the IP address corresponding to a MAC address

I've found this piece of code ( vbs was the original extension ) which gives
me the local IP address but I would like to enter a MAC address ( like
00-01-02-03-04-05 ) and then I would like in return the corresponding IP
address of the remote computer.

I'm not looking for code that gives me the MAC from an IP ( ping 1.1.1.1 and
arp -a will gives the answer)



strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set IPConfigSet = objWMIService.ExecQuery("Select IPAddress from
Win32_NetworkAdapterConfiguration where IPEnabled = TRUE")
For Each IPConfig In IPConfigSet
If Not IsNull(IPConfig.IPAddress) Then
For i = LBound(IPConfig.IPAddress) To UBound(IPConfig.IPAddress)
WScript.Echo IPConfig.IPAddress(i)
Next
End If
Next


Thanks for your help
J-Michel
 
You can use nbtstat -A and type the IP address which will return (at the
bottom of the listing) the MAC address. You could write a little script that
tries every possible IP address in the subnet and outputs the results to a
file. Not exactly what you're looking for, but maybe an alternative. (Note:
your computer would have to be in the same broadcast domain as the computers
you're checking).

....kurt
 
You can use nbtstat -A and type the IP address which will return (at the
bottom of the listing) the MAC address. You could write a little script that
tries every possible IP address in the subnet and outputs the results to a
file. Not exactly what you're looking for, but maybe an alternative. (Note:
your computer would have to be in the same broadcast domain as the computers
you're checking).

...kurt


If you ping an IP number and then do an arp -a the IP number shows
up, so in a script youi can do something like this

ping nn.nn.nn.nn | grep nn.nn.nn.nn

A little more scripting will extract the MAC number from the rest of
the info returned. the IP number has to be in the same mask, of
course.

Am I missing something ?
 
Hi all,

I have a question for you,

I'm looking for a way to have the IP address corresponding to a MAC address

I've found this piece of code ( vbs was the original extension ) which gives
me the local IP address but I would like to enter a MAC address ( like
00-01-02-03-04-05 ) and then I would like in return the corresponding IP
address of the remote computer.

I'm not looking for code that gives me the MAC from an IP ( ping 1.1.1.1 and
arp -a will gives the answer)



strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set IPConfigSet = objWMIService.ExecQuery("Select IPAddress from
Win32_NetworkAdapterConfiguration where IPEnabled = TRUE")
For Each IPConfig In IPConfigSet
If Not IsNull(IPConfig.IPAddress) Then
For i = LBound(IPConfig.IPAddress) To UBound(IPConfig.IPAddress)
WScript.Echo IPConfig.IPAddress(i)
Next
End If
Next


Thanks for your help
J-Michel


If you ping an IP number and get a response then do an arp -a you'll
find the MAC address, which could be grepped in a script.
 
Thanks kurt for your reply but Actually that was not the way I was thinking
doing the things but anyway I'm trying since this morning to write a script
using WSH ( and actually to execute VBscript code ) I wrote the logic but I
still missing a function to first ping a host, and secondly a function to
get the MAC address from the arp table.
I would prefer not to use the commands arp and ping, because I don't know
how to get the correct information and if the ping command fails, I don't
know how and even if it's possible to know the reason it failed


Jean-Michel
PS: I tried nbstat ( Windows XP doesn't have that command ) .
 
Thanks for you reply

but in the way you're leading me, how can I grep the info I need and not
all the rest of the output.

J-Michel
 
Thanks for you reply

but in the way you're leading me, how can I grep the info I need and not
all the rest of the output.

J-Michel


A small matter of scripting. :-)

I have the unix toolkit on all my machines.


ping can be a PITA to script because it waits and may not time out if
the IP is unreachable, but I imagine that any other network operation
that returns a succeed/fail status on a IP number should populate the
local arp table. If the operation fails then for all practical
purposes the machine doesn't exist.

Look at arp-a and then it's a small matter of programming.
 
Yes,
has you said a small matter of scripting ;-) but the small

anyway I'm writing and learning VBScript code at the same time and I'm sure
I will find the way to success :-)
I have almost the work done but I stil have to write the worst part, finding
the informations collected and write it in a file ( ok writing in a file is
tricky).

J-Michel
 
Finally I've finished the script but I still have to add more functionality
and certainly have a code more "Professionnal", if someone is intrested I
may send the script on the forum or to personnal email addresses.

thanks one more time for the ideas
J-Michel

Jean-Michel Cafagna said:
Yes,
has you said a small matter of scripting ;-) but the small

anyway I'm writing and learning VBScript code at the same time and I'm sure
I will find the way to success :-)
I have almost the work done but I stil have to write the worst part, finding
the informations collected and write it in a file ( ok writing in a file is
tricky).

J-Michel
 
Back
Top