wanip.py
Go to the documentation of this file.
00001 #! /usr/bin/env python
00002 
00003 """
00004 usage: %(progname)s hostname
00005 """
00006 
00007 import os, sys, string, time, getopt, re, urllib
00008 
00009 def usage(progname):
00010   print __doc__ % vars()
00011 
00012 def main(argv, stdout, environ):
00013   progname = argv[0]
00014   optlist, args = getopt.getopt(argv[1:], "", [])
00015 
00016   testflag = 0
00017   if len(args) == 0:
00018     usage(progname)
00019     return
00020 
00021   host = args[0]
00022 
00023   url = "http://%s/" % host
00024   fp = urllib.urlopen(url)
00025   body = fp.read()
00026   fp.close()
00027 
00028   body = re.sub('<[-=+/"A-Za-z0-9 ]*>', "", body)
00029   body = re.sub("&nbsp;", " ", body)
00030 
00031   pat = re.compile("WAN IP: ([0-9.]*)")
00032   m = pat.search(body)
00033   if m:
00034     wanip = m.group(1)
00035     print wanip
00036     return 0
00037   return 1
00038 
00039 if __name__ == "__main__":
00040   main(sys.argv, sys.stdout, os.environ)


wifi_ddwrt
Author(s): Scott Hassan , Eitan Marder-Eppstein
autogenerated on Thu Jun 6 2019 20:52:59