python 多线程,扫描域名是否可用

2020-10-15  本文已影响0人  随便写点什么就好

多线程

对于批量运维来说,多线程是必不可少的,服务器数量那么多,跑一遍下来,是需要非常多时间的.

import sys
import requests
import socket
import threading
import time

list_url = ['jira','confluence','jira7','git']
#修改成你需要扫描的域.
domain = ".baidu.cn"
list_http = []
for i in list_url:
    list_http.append(i+domain)

def getIP(domain):
  myaddr = socket.getaddrinfo(domain, 'http')
  return (myaddr[0][4][0])

def dd(url):
    try:
        domain_ip = getIP(url)
        domain_code = requests.get("http://"+url).status_code

        print("当前在处理url是: http://%s,    IP是: %s, 返回值是: %s" % (url,domain_ip,domain_code))
    except:
        print("当前在处理url是: http://%s, IP是:  返回值是: %s" % (url,"获取返回值失败"))

    try:
        domain_ip = getIP(url)
        domain_code = requests.get("https://"+url).status_code

        print("当前在处理url是: https://%s,    IP是: %s, 返回值是: %s" % (url,domain_ip,domain_code))
    except:
        print("当前在处理url是: https://%s, IP是:  返回值是: %s" % (url,"获取返回值失败"))

if __name__ == '__main__':
    for i in list_http:
        t = threading.Thread(target=dd,args=(i,))
        t.start()
        #多线程执行,需要注意锁
        t.join()
image.pngimage.png
上一篇下一篇

猜你喜欢

热点阅读