11 usage
= "Usage: %prog [-e] [-i] [-l]"
12 parser
= optparse
.OptionParser(usage
=usage
)
14 parser
.add_option("-e", "--ext", action
="store_true", dest
="ext",
15 help="show external IP",
18 parser
.add_option("-i", "--int", action
="store_true", dest
="int",
19 help="show internal IP",
22 parser
.add_option("-l", "--lan", action
="store_true", dest
="lan",
23 help="show wlan ESSID. Default if no args",
29 def getasfile(name
, pth
=""):
30 if sys
.platform
.startswith('linux'):
31 if os
.path
.exists('/sbin/' + name
):
33 elif os
.path
.exists('/usr/sbin/' + name
):
34 pth
= '/usr/sbin/' + name
36 proc
= subprocess
.Popen(pth
, stdout
=subprocess
.PIPE
,
37 stderr
=subprocess
.PIPE
)
38 return proc
.communicate()[0].split('\n')
43 for line
in getasfile('ifconfig'):
44 if re
.search('Bcast:', line
):
45 line
= line
.split(':')
46 return line
[1].split(' ')[0]
49 x
= urllib
.urlopen('http://ip.cutup.org/')
53 for line
in getasfile('iwconfig'):
54 if (line
.startswith('eth') and re
.search('ESSID', line
)
55 and not re
.search('NOT READY', line
)):
56 line
= line
.split(r
'"')
59 if "__main__" == __name__
:
60 parser
= buildparser()
61 opts
, args
= parser
.parse_args()