Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting local subnet mask




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:
http://lists.apple.com/mailman/options/macnetworkprog/email@hidden

This email sent to email@hidden
References: 
 >Getting local subnet mask (From: "Hamish Allan" <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.