zoukankan      html  css  js  c++  java
  • 新浪检查前端机脚本

     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()
  • 相关阅读:
    Linux进程和线程
    Vim编辑器
    Java多线程编程(七)线程状态、线程组与异常处理
    Java多线程编程(六)单例模式与多线程
    Integer to Roman
    Container With Most Water
    Regular Expression Matching
    Palindrome Number
    c/c++获取硬盘序列号
    String to Integer (atoi)
  • 原文地址:https://www.cnblogs.com/aboys/p/3105707.html
Copyright © 2011-2022 走看看