ErosOlmi
03-05-2007, 17:41
Today I needed to know which IP on our lan had what Mac address.
How to do? You can use Arp or GetMac or other tools around but you can make the job also using scripts, in this case a thinBasic script.
Here the code:
'---------
' Modules
'---
uses "inet"
uses "console"
'---------
' Constants
'---
%MaxIp = 255
%Pos_IP = 1
%Pos_Results = 2
%Pos_Mac = 3
'---------
' Variables
'---
dim Counter as long '---Used to count IPs
dim sIP as string '---Used to form full IP
dim sSubNet as string '---Store initial subnet
dim sResults(3, %MaxIp) as string '---Store results
'---------
' Script
'---
'---Indicate here your lan
sSubNet = "10.10.130."
'---
for Counter = 1 to %MaxIp
sIP = sSubNet & Counter
sResults(%Pos_IP , Counter) = sIP
sResults(%Pos_Results , Counter) = INET_Ping(sIP, 100, "abcdefghijklmnopqrstu")
sResults(%Pos_Mac , Counter) = INET_GetRemoteMACAddress(sIP)
Console_writeline _
format$(Counter, "000") & " " & _
using$("\ \", sResults(%Pos_IP, Counter)) & _
using$("\ \", parse$(sResults(%Pos_Results, Counter), $tab, 3)) & _
sResults(%Pos_Mac, Counter) & _
""
next
'---Here you can do what you need with IP and mac address pair.
console_waitkey
How to do? You can use Arp or GetMac or other tools around but you can make the job also using scripts, in this case a thinBasic script.
Here the code:
'---------
' Modules
'---
uses "inet"
uses "console"
'---------
' Constants
'---
%MaxIp = 255
%Pos_IP = 1
%Pos_Results = 2
%Pos_Mac = 3
'---------
' Variables
'---
dim Counter as long '---Used to count IPs
dim sIP as string '---Used to form full IP
dim sSubNet as string '---Store initial subnet
dim sResults(3, %MaxIp) as string '---Store results
'---------
' Script
'---
'---Indicate here your lan
sSubNet = "10.10.130."
'---
for Counter = 1 to %MaxIp
sIP = sSubNet & Counter
sResults(%Pos_IP , Counter) = sIP
sResults(%Pos_Results , Counter) = INET_Ping(sIP, 100, "abcdefghijklmnopqrstu")
sResults(%Pos_Mac , Counter) = INET_GetRemoteMACAddress(sIP)
Console_writeline _
format$(Counter, "000") & " " & _
using$("\ \", sResults(%Pos_IP, Counter)) & _
using$("\ \", parse$(sResults(%Pos_Results, Counter), $tab, 3)) & _
sResults(%Pos_Mac, Counter) & _
""
next
'---Here you can do what you need with IP and mac address pair.
console_waitkey