Created
May 8, 2015 02:01
-
-
Save BenTheHokie/ed7646eaf6e0fd66e5f3 to your computer and use it in GitHub Desktop.
The mystical magical regex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import re, os | |
def getIP(): | |
jargon = os.popen('/sbin/ip -o -4 addr list').read().split('\n') | |
getip = re.compile('[0-9]+: (?P<conn>[A-Za-z0-9]+)( +)inet (?P<addr>([12]?([0-9])+\.){3}([12]?([0-9])+)/[0-9]{1,2})') | |
retval = [] | |
for a in jargon: | |
tmp = getip.search(a) | |
if tmp: | |
retval.append( | |
{ | |
'conn' : tmp.group('conn'), | |
'addr' : tmp.group('addr') | |
} | |
) | |
return retval |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment