python3實現IP地址查詢工具


import requests
from bs4 import BeautifulSoup
import re

url = 'https://www.ipip.net/ip.html'
while True:
    ip = input('輸入你要查詢的IP:')
    data = {'ip': ip}
    header = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36'}
    r = requests.post(url, data=data, headers=header)
    r.encoding = 'utf-8'
    html = r.text
    soup = BeautifulSoup(html, 'html.parser')
    span = soup.find_all(name=['span', 'a'])
    ip = re.findall('<a href=".*?style="background: none;color: #0A246A;width: auto;">(.*?)</a>', str(span))
    localtion = re.findall(
        '<span style="display: inline-block;text-align: center;width: 720px;float: left;line-height: 46px;height: 46px;">(.*?)</span>, <span style="float: right">',
        str(span))
    print('------ipip地址查詢工具------')
    print('當前查詢的ip為:' + str(ip))
    print('當前查詢的ip地址為:' + str(localtion))

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM