# 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 & nbsp; (. +? % )'
Car = re. compile (cartridge)
Cartridge = re. findall (car, html)
Rekit = r'maintenance Kit & nbsp; (. +? % )'
Kit = re. compile (rekit)
Kit = re. findall (kit, html)
Print "Cartridge = % s" % Cartridge,
Print "Kit = % s" % Kit
Def getData_TFNRCPRT02 (html ):
Cartridge = R' & nbsp; (. +? % )'
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.135690.171/hp/device/this. LCDispatcher ': 'galprt04 ',
'Http: // 10.135690.172/hp/device/this. LCDispatcher ': 'galprt05 ',
'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"