Skip to content
Advertisement

Is there any way to get Network Address with subnet mask with python?

I am trying to scan my local area network information with python. Is there any way to get Network Address with subnet mask information to python?

I want to get the Network Address (local network) and subnet mask information in the variables But when I searched on google, seems like there is no relevant information Thank you!!

Advertisement

Answer

I think this will be helpful to get local network information in your case this might be os dependent.

import netifaces
netifaces.interfaces()

#>>[‘lo0’, ‘gif0’, ‘stf0’, ‘en0’, ‘en1’, ‘fw0’]

netifaces.ifaddresses(‘lo0’)

#>>{18: [{‘addr’: ”}], 2: [{‘peer’: ‘127.0.0.1’, ‘netmask’: ‘255.0.0.0’, ‘addr’: ‘127.0.0.1’}], 30: [{‘peer’: ‘::1’, ‘netmask’: ‘ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff’, ‘addr’: ‘::1’}, {‘peer’: ”, ‘netmask’: ‘ffff:ffff:ffff:ffff::’, ‘addr’: ‘fe80::1%lo0’}]}=[‘lo0’, ‘gif0’, ‘stf0’, ‘en0’, ‘en1’, ‘fw0’]

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement