Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the simply-static domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /var/www/html/wp-includes/functions.php on line 6121
获取自己的ip地址数据库

获取自己的ip地址数据库

import requests
from bs4 import BeautifulSoup
import re
import time
iplist=''
def getpublicip():
    t=requests.get("http://txt.go.sohu.com/ip/soip")
    nums=(t.text.find('window.sohu_user_ip='))
    pre_ip=(t.text[(nums+21):(nums+21+15)])
    ip = pre_ip.split('"')[0]
    return ip
for a in range(0,255):
    for b in range(0,255):
        for c in range(0,255):
            for d in range(0,255):
                ip=str(a)+'.'+str(b)+'.'+str(c)+'.'+str(d)
                url = "https://www.ip138.com/iplookup.asp?ip={}&action=2".format(ip)
                headers = {
                    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.100 Safari/537.36'
                }
                # 获取响应
                response = requests.get(url=url, headers=headers)
                response.encoding = "gb2312"
                html = response.text
                time.sleep(0.05)
                for match in re.finditer('"(ip|prov|city|ct)":"(.*?)"',html):
                    print(ip+':'+match.group())
                    with open('ip2city.txt',mode='a',encoding='utf-8') as f:
                        f.write(ip+','+iplist.join(match.group())+'\n')

http://ip.bczs.net/city/320100