#coding:utf-8
import re,os,urllib,string
def getHtml(url):
page = urllib.urlopen(url)
html = page.read()
return html
def getData(html):
cartridge = r'Black Print Cartridge (.+?%)'
car = re.compile(cartridge)
Cartridge = re.findall(car,html)
rekit = r'Maintenance Kit (.+?%)'
kit = re.compile(rekit)
Kit = re.findall(kit,html)
print "Cartridge=%s" % Cartridge,
print "Kit=%s" % Kit
def getData_TFNRCPRT02(html):
cartridge = r' (.+?%)'
car = re.compile(cartridge)
Cartridge = re.findall(car,html)
print "Cartridge=%s" % Cartridge
def IpStatus(ip):
Status = os.system("ping" + " " + ip)
return Status
def getIp(url):
getIp = r'http://(.+?)/'
GetIp = re.compile(getIp)
IpAddress = re.findall(GetIp,url)
ip = ''.join(IpAddress)
return ip
UrlDir = {
'http://10.132.160.171/hp/device/this.LCDispatcher' : 'LegalPrt04',
'http://10.132.160.172/hp/device/this.LCDispatcher' : 'LegalPrt05',
'http://10.153.24.177/hp/device/this.LCDispatcher' : 'SzPrt11' ,
'http://10.153.24.172/hp/device/this.LCDispatcher' : 'SzPrt13' ,
'http://10.153.26.179/hp/device/this.LCDispatcher' : 'SzPrt14' ,
'http://10.186.65.156/hp/device/this.LCDispatcher' : 'TfnrcPrt01',
'http://10.186.65.101/' : 'TfnrcPrt3390',
'http://10.153.25.200/' : 'SzPrt16'
}
for url in UrlDir:
ip = getIp(url)
Status = IpStatus(ip)
if Status == 0:
if url == 'http://10.186.65.101/':
html = getHtml(url)
print UrlDir[url]+":",
getData_TFNRCPRT02(html)
elif url == 'http://10.153.25.200/':
print "SZPRT16 is OK"
else:
html = getHtml(url)
print UrlDir[url]+":",
getData(html)
else:
print UrlDir[url] + ":"+"Ping fail"