wanip.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 
3 """
4 usage: %(progname)s hostname
5 """
6 
7 import os, sys, string, time, getopt, re, urllib
8 
9 def usage(progname):
10  print __doc__ % vars()
11 
12 def main(argv, stdout, environ):
13  progname = argv[0]
14  optlist, args = getopt.getopt(argv[1:], "", [])
15 
16  testflag = 0
17  if len(args) == 0:
18  usage(progname)
19  return
20 
21  host = args[0]
22 
23  url = "http://%s/" % host
24  fp = urllib.urlopen(url)
25  body = fp.read()
26  fp.close()
27 
28  body = re.sub('<[-=+/"A-Za-z0-9 ]*>', "", body)
29  body = re.sub("&nbsp;", " ", body)
30 
31  pat = re.compile("WAN IP: ([0-9.]*)")
32  m = pat.search(body)
33  if m:
34  wanip = m.group(1)
35  print wanip
36  return 0
37  return 1
38 
39 if __name__ == "__main__":
40  main(sys.argv, sys.stdout, os.environ)
def main(argv, stdout, environ)
Definition: wanip.py:12
def usage(progname)
Definition: wanip.py:9


wifi_ddwrt
Author(s): Scott Hassan , Eitan Marder-Eppstein
autogenerated on Wed May 12 2021 02:21:31