I have the start of the batch script to a point done, but it probably needs
a lot more work to accomplish everything.
Current script: mac.bat
-------------------
for /L %%z in (50,1,200) do @ping 192.168.1.%%z -w 10 -n 1 | find "Reply"
arp -a >arp.txt
type arp.txt |find /i"%1"
-------------------
End script
So currently we can do mac.bat xx-xx and it will return the ip address with
that mac address. Just getting this far seems like a miracle to me. Is
there a way to extend it to get the full functionality I'm hoping for? The
biggest thing I'd like to do is make the script prompt the user for the mac
address, instead of having to open of command prompt and enter it as
mac.bat xx-xx. If we can get it to open iexplore as well, that would just
be icing on the cake.
Does it have to be dynamic? Are the IP addresses static?
Can you create a list of MAC to IP addresses and search that when you
need to find one?
--
Regards,
Mic
> Does it have to be dynamic? Are the IP addresses static?
> Can you create a list of MAC to IP addresses and search that when you
> need to find one?
Yes it has to be dynamic. It must create the arp table with the mac
addresses at run-time. The ip addresses are not static, they will be after
we get done with internet explorer (that is the point of this exercise), to
make them static, but the first time they are plugged in they will be
dynamic.
>Quick overview of what I'd like to accomplish:
>1) User double clicks a file, enters the last 4 digits of a mac address
>2) The script finds the ip address associated with that mac address
>3) Internet explorer opens that ip address
>
>I have the start of the batch script to a point done, but it probably needs
>a lot more work to accomplish everything.
>
>Current script: mac.bat
>-------------------
>for /L %%z in (50,1,200) do @ping 192.168.1.%%z -w 10 -n 1 | find "Reply"
>arp -a >arp.txt
>type arp.txt |find /i"%1"
>-------------------
>End script
This is untested:
@echo off
set /p "macpart=last 5 characters of the MAC address xx-xx : "
for /L %%z in (50,1,200) do (
ping 192.168.1.%%z -w 10 -n 1 | find "TTL=">nul && (
arp -a 192.168.1.%%z |find "%macpart% ">nul && (
start "" http://192.168.1.%%z
)
)
)
--
Regards,
Mic
My suggestion would be to run the arp out to a file like the OP did
originally and only run the ping sweep if the mac isn't found. This way,
you'll most likely only have to run the ping sweep once. Pinging 150 IP's
every time the script runs isn't very efficient. The IP's only stay in cache
for about 90 seconds so writing out to the file is necessary. Here is what I
came up with prior to seeing your reply Mic.
Untested..
@echo off
setlocal
cd /d %~dp0
set ie="C:\Program Files\Internet Explorer\iexplore.exe"
set mac=%~1
if "%~1" EQU "" set /p mac=Enter MAC address:
:findagain
arp -a>arp.txt
for /f "tokens=1" %%a in (
'type arp.txt^|find /i "%mac%"'
) do (if errorlevel 0 (set ip=%%a
) ELSE (
for /L %%z in (50,1,200) do (
@ping 192.168.1.%%z -w 10 -n 1 | find "TTL="
)
goto :findagain
)
)
echo start "" %ie% http://%ip%
HTH
Matt
>My suggestion would be to run the arp out to a file like the OP did
>originally and only run the ping sweep if the mac isn't found. This way,
>you'll most likely only have to run the ping sweep once. Pinging 150 IP's
>every time the script runs isn't very efficient.
He said in a reply that the IP addresses were dynamic and so needed to
it be a dynamic sweep.
>arp -a>arp.txt
Doesn't that just return the local machine's MAC addresses?
--
Regards,
Mic
>>arp -a>arp.txt
>
> Doesn't that just return the local machine's MAC addresses?
That is correct, that line is what you get the mac addresses from. Your
first solution did work. My newsreader deleted the first few messages from
the thread, it froze up on me.
But your solution worked great, thanks!
I guess it depends on what the lease time is and how often this will be
running. It takes about 30-40 seconds to ping 150 ips from my machine and if
you're running this one after another after another, there would be some
time savings by not doing the sweep every time.
>>arp -a>arp.txt
>
> Doesn't that just return the local machine's MAC addresses?
>
Yes, but it will have the entire list from the ping sweep cached for about
90 seconds.
In that case you don't need the ping command because the arp command is
querying the remote machine directly, I think.
@echo off
set /p "macpart=last 5 characters of the MAC address xx-xx : "
for /L %%z in (50,1,200) do (
arp -a 192.168.1.%%z |find "%macpart% ">nul && (
start "" http://192.168.1.%%z
)
)
--
Regards,
Mic
> In that case you don't need the ping command because the arp command is
> querying the remote machine directly, I think.
I think the ping is necessary to "wake up" the remote machines. I think it
is necessary, the script seemed to be an infinite loop without it. Nothing
ever happened.
Try this as a test - see if the IP address increments.
If the machines are in standby then they will need to wake up.
@echo off
set /p "macpart=last 5 characters of the MAC address xx-xx : "
for /L %%z in (50,1,200) do (
echo querying 192.168.1.%%z
>foxidrive wrote:
>
>> for /L %%z in (50,1,200) do (
>> echo querying 192.168.1.%%z
>> arp -a 192.168.1.%%z
>
>
>Localhost must make contact with remote before arp.exe can perform a
>lookup in the ip<=>if mapping table. The arp.exe only performs
>lookups/adds/deletes of ip<=>if mappings on localhost.
Ok. Thanks for the info.
I've tested it here on the LAN and it does do as you say.
--
Regards,
Mic
I don't understand; you can get anyone's IP easily as long as they're
connected to you. Even HTML has that ability. What might I be missing that
the MAC address is needed?
HTH,
Twayne`
> I don't understand; you can get anyone's IP easily as long as they're
> connected to you. Even HTML has that ability. What might I be missing
> that the MAC address is needed?
At work we have some drive plc's that must be configured for the network
before they can be installed. We used to use a crossover cable to achieve
this, but the replacement drives have went to dhcp only. When they come in
they are dhcp, so I plug it into the network and it gets assigned an ip
address, but I have no way of knowing what it is, since I am not on the
network team. (And the drives do not have a way of telling us, they are
just pure hardware, no displays or anything.)
The workaround was for me to use a cheap router, but trying to teach shop
guys all of those steps was cumbersome. This batch file makes it much much
simpler. Plug the drive into the faceplate, run this file, type in the last
4 digits of the mac and boom it opens up internet explorer and they are
ready to configure the drives.
This really helped us out a lot. Thanks for all of the help.
>At work we have some drive plc's that must be configured for the network
>before they can be installed. We used to use a crossover cable to achieve
>this, but the replacement drives have went to dhcp only. When they come in
>they are dhcp, so I plug it into the network and it gets assigned an ip
>address, but I have no way of knowing what it is, since I am not on the
>network team. (And the drives do not have a way of telling us, they are
>just pure hardware, no displays or anything.)
>
>The workaround was for me to use a cheap router, but trying to teach shop
>guys all of those steps was cumbersome. This batch file makes it much much
>simpler. Plug the drive into the faceplate, run this file, type in the last
>4 digits of the mac and boom it opens up internet explorer and they are
>ready to configure the drives.
>
>This really helped us out a lot. Thanks for all of the help.
Thanks for the explanation... it's interesting to hear how it solved
your issue.
--
Regards,
Mic