python [url—>ip]脚本

发布于 2020-09-05  127 次阅读


0x01 代码

#!/usr/bin/python3
import sys,socket,threading,time

def main(host):
    try:
        if '/' in host:
            target= (host.split('/')[2])
            ip = socket.gethostbyname(target)
            result(ip)
        else:
            ip = socket.gethostbyname(host)
            result(ip)
    except:
        pass
 
def result(ip):
    r = open('ip.txt', 'a+')
    with open('ip.txt') as f:
        if ip not in f.read():
            print(ip)
            r.write(ip + '\n')
            r.close()

if __name__ == '__main__':
    if len(sys.argv) == 2:
        url = sys.argv[1]
        f = open(url,'r')
        for i in f:
            host = i.rstrip('\n')
            t = threading.Thread(target=main,args=(host,))
            t.start()
            time.sleep(0.001)
    else:
        print("Tips:python3 url-ip.py url.txt")


我不懂世界到底在热闹些什么