I need to create a Python script that queries the network interfaces and returns me the name of the host, the IP address, and the mac address.
#!/usr/bin/env python3
import netifaces
x = netifaces.interfaces()
i = x[0]
for i in x:
if i != 'lo':
print(i)
face = netifaces.ifaddresses(i)
print(face)
i += i
else:
continue
This is one version of the program I am working with. This seems to grab all the data that I need but I cannot get it to print clean or correctly! I am looking for something like: "Nic: wlan0, ipaddr: 10.0.0.1, mac: 4651168584541"
I am new to programming and very new to python so please any help is appreciated!
So this was a little tricky at first but this format should allow you to grab data from the results of netifaces.
Output will look as follows: