1 #!/usr/bin/python 2 import urllib2 3 4 server_list = [] 5 product_list = ['/dpool/hdpic/index.php'] 6 7 def main(): 8 for ip in server_list: 9 for product in product_list: 10 url = 'http://%s%s' % (ip, product) 11 request = urllib2.Request(url) 12 request.add_header('Host', 'dp.sina.cn'); 13 try: 14 response = urllib2.urlopen(request) 15 print url 16 except urllib2.HTTPError, e: 17 print "Code:%s Msg:%s Url:%s Ip:%s" % (e.code, e.reason, url, ip) 18 19 if __name__ == '__main__': 20 main()
在日常维护过程中经常要检查负责的产品页面情况,随时有新上线的前端机要我们测试,所以诞生了此工具脚本,Like Python
MD优化了一下
#!/usr/bin/python import urllib2 import os import re server_list = [] lines = os.popen('host ******* | sort').readlines() for line in lines: s = re.search('(\.?\d+){4}', line) if s: server_list.append(s.group()) product_list = ['/dpool/hdpic/index.php'] def main(): for ip in server_list: for product in product_list: url = 'http://%s%s' % (ip, product) request = urllib2.Request(url) request.add_header('Host', 'dp.sina.cn'); try: response = urllib2.urlopen(request) print url except urllib2.HTTPError, e: print "Code:%s Msg:%s Url:%s Ip:%s" % (e.code, e.reason, url, ip) except urllib2.URLError, e: print "Code:%s Msg:%s Url:%s Ip:%s" % (e.code, e.reason, url, ip) if __name__ == '__main__': main()