• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Getting local subnet mask
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


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

  • Prev by Date: Re: Getting local subnet mask
  • Next by Date: CFReadStreamOpen 550 error
  • Previous by thread: Re: Getting local subnet mask
  • Next by thread: CFReadStreamOpen 550 error
  • Index(es):
    • Date
    • Thread