Re: Getting local subnet mask
Re: Getting local subnet mask
- Subject: Re: Getting local subnet mask
- From: Nathan Duran <email@hidden>
- Date: Thu, 28 Feb 2008 18:55:23 -0800
On Feb 28, 2008, at 4:54 PM, Hamish Allan wrote:
Preferably in cross-platform Python, but beggars can't be choosers :)
Or try:
---
import os, re
iffinder = re.compile(r'^(?P<interface>\S+):')
maskfinder = re.compile(r'netmask\s(?P<mask>0x\S{8})')
masks = {}
curif = None
for line in os.popen("ifconfig -a"):
match = iffinder.search(line)
if match:
curif = match.group('interface')
continue
match = maskfinder.search(line)
if match and curif:
masks[curif] = match.group('mask')
curif = None
continue
print masks
---
Sample output:
{'en0': '0xffffff00', 'lo0': '0xff000000'}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden