Many large websites use multiple server (IP) addresses to provide services for a single website to relieve stress and avoid spof. This includes using DNS round training for load balancing. But for administrators, how can they monitor these servers? The following script can help you implement it. Importsocket, urllib. parse
Many large websites use multiple server (IP) addresses to provide services for a single website to relieve stress and avoid spof.
This includes using DNS round training for load balancing.
But for administrators, how can they monitor these servers?
The following script can help you implement it.
- ImportSocket, urllib. parse, configparser, re, sys, http. client,Time
- # Coding: UTF-8
- # Domain Name Translation IP address Function
- DefDom2ip (dname ):
- Iplist = socket. gethostbyname _Ex(Dname )[2]
- ReturnIplist
- # Dictionary data generation function
- DefParse (url, key ):
- Zhlist [key] = {}
- Zhlist [key] [\ 'Host \'] = A. hostname
- Zhlist [key] [\ 'Path \'] = A. path
- Zhlist [key] [\ 'Port \'] = A. port
- Zhlist [key] [\ 'Query \'] = A. query
- Zhlist [key] [\ 'Url \'] = A. geturl ()
- TrY:
- Zhlist [key] [\ 'Ips \'] = Dom2ip (a. hostname)
- ExceptException as err:
- Print(\ 'Your configuration file format is incorrect, n error message :\', Err,\ 'N' program exited \')
- Sys. exit (1)
- # Headers
- Headers = {
- \ 'User-Agent \':\ 'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.1 (KHTML, like Gecko )\'
- }
- DefGetinfo (domain, ip, path =\'/\', Port =80):
- Headers [\ 'Host \'] = Domain
- H = http. client. HTTPConnection (ip, port, timeout =8)
- H. request (\ 'Get \', Path, headers = headers)
- R = h. getresponse ()
- Print(R. getheaders ())
- Print(\ 'Server return status \', R.StatUs)
- Print(\ 'Server return Result \', R. reason)
- Print(\ 'Destination time :\', R. getheader (\ 'Date \'))
- Print(\ 'Target Web end :\', R. getheader (\ 'Server \'))
- Print(\ 'Last modification time of the target webpage :\', R. getheader (\ 'Last-ModifiEd\'))
- Print(\ 'Target content returned :\', R. getheader (\ 'Content-Length \'),\ 'Byte \')
- Print(\ 'Destination return code :\', R. getheader (\ 'Content-ENcOding \'))
- Try:
- # Analyze the character set of a web page
- A = r. getheader (\ 'Content-Type \')
- B = re.FindAll (\ 'CharSet= (. *) $ \', A, re. I)
- ForIInB:
- Charset = I
- Try:
- Charset
- Res = res. decode (charset,\ 'Ignore \')
- Except:
- Res = r. read (2048)