[fpc-pascal] How to list IP and MAC of network adapters on Windows?

Bo Berglund bo.berglund at gmail.com
Fri Sep 10 09:03:30 CEST 2021


Is there a way to enumerate the active adapters on a Windows computer with their
IPv4 and MAC addresses?

I am trying to convert a Linux reporting script to Windows, but I have a hard
time finding a suitable Windows command. The script uses common Linux commands
and tools to get the eth0 and wlan0 data (IPv4 and MAC addresses) and then to
POST it to my website mailer (php script) via curl. See below.

I have curl on Windows too so once the data are found the same command can be
used here as well, but the network info extraction seems to be a lot harder.

So I figured I could write a small FPC command line tool to extract this
information and use it in the batch file.

But is there some such call available in FPC or standard packages like LNet or
similar?

On Linux I can do this in the bash script:

MyName=$(hostname)
IPAddr=$(ifconfig eth0|grep "inet "|sed 's/ *inet //;s/ .*//')
IPAddrWiFi=$(ifconfig wlan0|grep "inet "|sed 's/ *inet //;s/ .*//')
IPMac=$(ifconfig eth0 | grep -Eo ..\(\:..\){5})
IPMacWiFi=$(ifconfig wlan0 | grep -Eo ..\(\:..\){5})

I don't believe there is a similar command line way on Windows, so therefore I
ask for a FPC way of getting it.


-- 
Bo Berglund
Developer in Sweden



More information about the fpc-pascal mailing list