首页 > 其他分享 >IP/域名/SEO/便利查询脚本

IP/域名/SEO/便利查询脚本

时间:2023-01-12 22:35:51浏览次数:54  
标签:engine domain IP 查询 print 域名 result SEO input

为了方便平时对IP以及涉及的域名进行相关信息查询,用python写了一个简单的脚本,方便平时使用。主要利用到ip138网站进行IP反查和域名IP解析记录查询以及爱站网相关域名权重查询。欢迎师傅们进行相关优化,脚本代码如下:

import sys
import time
import requests
from lxml import etree


# ip查询域名或域名解析查询
def query(ip_or_domain):
    url = "https://site.ip138.com/{}/".format(ip_or_domain)
    headers = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:108.0) Gecko/20100101 Firefox/108.0",
        "Accept": "* / *"
    }
    response = requests.get(url, headers=headers)
    # print(response.text)
    if module == 1:
        ipResult(response)
    if module == 2:
        domainResult(response)


# SEO权重查询
def query_seo(domain):
    url = "https://www.aizhan.com/cha/{}/".format(domain)
    headers = {
        "Cookie": "Hm_lvt_b37205f3f69d03924c5447d020c09192=1672124272,1672735140,1673514737; _csrf=a0f57c688194fe82afecf61cbea74d0da248568a19474440a60b66646046e3b0a%3A2%3A%7Bi%3A0%3Bs%3A5%3A%22_csrf%22%3Bi%3A1%3Bs%3A32%3A%22sNoA1RLB3SXLCr_--Dgjfu6J-8PtyCfy%22%3B%7D; allSites=www.baidu.com%7Cpassport.vivo.com.cn%7Cexp.scjgj.sh.gov.cn%7Ccoscoairprod.5156.com.cn%7Cjiekou.sz517.com%7Cgo.huanqiu.com%7Cmiaozhan-admin.sto.cn%7Cshenyunduo.sto.cn%7Cassets.plesk.com%7Capp.mokahr.com; Hm_lpvt_b37205f3f69d03924c5447d020c09192=1673516067",
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36"
    }
    response = requests.get(url, headers=headers)
    # print(response.text)
    SEOResult(response)


# 匹配IP查询结果
def ipResult(response):
    # 利用etree.HTML将字符串解析为HTML文档
    html = etree.HTML(response.text)
    # print(type(html))
    date_result = html.xpath('//ul[@id="list"]/li/span//text()')
    domain_result = html.xpath('//ul[@id="list"]/li/a//text()')
    error_result = html.xpath('//p[@class="error"]//text()')
    # print(type(date))
    # print(len(date))
    # print(len(error))
    if len(error_result) == 1:
        print("禁止查询该IP!!!")
    else:
        formatIPResult(date_result, domain_result)


# 匹配域名查询结果
def domainResult(response):
    # 利用etree.HTML将字符串解析为HTML文档
    html = etree.HTML(response.text)
    # print(html)
    domain_result = html.xpath('//div[@id="J_ip_history"]//text()')
    error_result = html.xpath('//p[@class="error"]//text()')
    # print(type(domain_result))
    # print(type(domain_result))
    # print(len(domain))
    if len(error_result) == 1:
        print("禁止查询该域名!!!")
    else:
        formatDomainResult(domain_result)


# 匹配SEO查询结果
def SEOResult(response):
    html = etree.HTML(response.text)
    # print(html)
    engine_result = html.xpath('//table[@class="table"]//li/text()')
    weight_result = html.xpath('//table[@class="table"]//img/@src')
    # print(engine_result)
    # print(weight_result)
    formatSEOResult(engine_result, weight_result)


# 美化打印IP查询结果
def formatIPResult(date_result, domain_result):
    print("==================" + input_ip + date_result[0] + "================")
    for i in date_result:
        if date_result.index(i) != 0:
            print(date_result[date_result.index(i)] + ":", end="")
            print(domain_result[date_result.index(i) - 1])


# 美化打印域名查询结果
def formatDomainResult(domain_result):
    list_ = []
    print("==================" + input_domain + "历史IP解析记录如下:" + "=================")
    # 去除解析获取列表中换行符并将其数据存储至新的list_列表
    for i in domain_result:
        if i.strip():
            list_.append(i.strip())
    # print(list_)
    for i in list_:
        if list_.index(i) % 2 == 0:
            # print(list_.index(i))
            print(i + ":", end="")
        else:
            print(i)


# 美化打印SEO匹配结果
def formatSEOResult(engine_result, weight_result):
    engine_name = []
    weight_value = []
    print("==================" + input_domain + " SEO综合查询如下:" + "=================")
    for i in engine_result:
        if 5 < engine_result.index(i) < 12:
            # print(i)
            engine_name.append(i)
    del weight_result[0]  # 删除列表第一个值
    # print(weight_result)
    for j in weight_result:
        # print(j)
        # print(j.split('/')[-1])
        # print(j.split('/')[-1].split('.')[0])
        value = j.split('/')[-1].split('.')[0]    # 通过获取的图片url,进行优化提取权重值
        # print(value)
        weight_value.append(value)
    # print(engine_name)
    # print(weight_value)
    for k in engine_name:
        print(engine_name[engine_name.index(k)], end="")
        print(weight_value[engine_name.index(k)])


if __name__ == "__main__":
    # 获取当前时间
    # localtime = time.strftime('%Y-%m-%D %H-%M-%S', time.localtime())
    print("==================IP/域名/SEO查询========Author:magic_rookie==")
    flag = 1
    while flag:
        try:
            module = int(input("请输入要查询的功能(1.IP查询 2.域名查询 3.SEO查询 0.退出程序):"))
            # print(type(int(module)))
            # i = 3
            # print(type(i))
            if module < 0 or module > 3:
                sys.exit()
            if module == 1:
                # input_ip = "123.6.81.231"
                input_ip = input("请输入要查询的IP:")
                query(input_ip)
            if module == 2:
                # input_domain = "hydcd.com"
                input_domain = input("请输入要查询的域名:")
                query(input_domain)
            if module == 3:
                # input_domain = "www.baidu.com"
                input_domain = input("请输入要查询的域名:")
                query_seo(input_domain)
            if module == 0:
                flag = 0
                print("程序退出!!!")
        except:
            print("输入有误或程序运行异常或网络异常,请重试!!!")

运行结果:

标签:engine,domain,IP,查询,print,域名,result,SEO,input
From: https://www.cnblogs.com/magic-rookie/p/17048119.html

相关文章

  • 将ipynb文件转成pdf
    本文内容:将GitHub上ipynb源码格式的书籍转成pdf应用场景:GitHub上某些书籍按章节使用ipynb格式存储(Jupyter创建了一种良好的交互方式,即将程序说明和代码放在同一个文档中......
  • JavaScript表单form
    form表单实例1<!DOCTYPEhtml>2<html>3<head>4<metacharset="utf-8">5<title>javascriptform表单</title>6</head>7......
  • 【每日一读】Sampling Multiple Nodes in Large Networks: Beyond Random Walks
    目录​​简介​​​​论文简介​​​​ABSTRACT​​​​1INTRODUCTION​​​​1.1OurContribution​​​​1.2RelatedWork​​​​2LOWERBOUNDFORRANDOMWALKS​​......
  • elasticsearch实现简单的脚本排序(script sort)
    目录1、背景2、分析3、构建数据3.1mapping3.2插入数据4、实现4.1根据省升序排序4.1.1dsl4.1.2运行结果4.2湖北省排第一4.2.1dsl4.2.2运行结果4.3湖北省排第一,其余......
  • PIPOJ 最短距离
    题目描述小王和小明是好朋友,两人最开始各有一个初始位置p和一个恒定速度v,从0时刻起开始,他们从初始位置以恒定速度开始行走,请告诉我行走过程中两人的最短距离是多少......
  • 创变8年,iPayLinks如何成为企业出海道路上“靠谱的伙伴”
    2022年对于全球经济而言是不平凡的一年,俄乌冲突爆发、天然气等能源价格大幅飙升、全球通胀水平创纪录……外贸企业与跨境电商行业作为全球经济发展的“毛细血管”,在这一......
  • JavaScript 原型和原型链
    JavaScript是一种基于原型继承的语言。在JavaScript中,对象是通过原型链来继承属性和方法的。一、原型每一个对象都有一个proto属性,该属性指向该对象的原型。原型本......
  • 【Vue3.0】关于 script setup 语法糖的用法
    scriptsetup-简介先来看一看官网关于<scriptsetup>的介绍:要彻底的了解setup语法糖,你必须先明确setup()这个组合式API官网中对于这一api的介绍是——在se......
  • Linux基础13 打包压缩 gzip, zip, tar
    压缩打包 windows下我们接触最多的压缩文件就是.rar格式,但Linux有自己所特有的压缩工具。 一般linux上的压缩包windows上可以使用 如果希望windows和Linux互相能使用的压......
  • 【校招VIP】“推推”Java项目课程:开发文档-榜单小说在更新时间前后的访问压力
    今天接着来看商业实战项目推推的第一个模块——小说详情模块的开发文档设计。我们上节课看了产品经理给出来的产品功能要求以及一些关键的重难点。这个也是能力提升的一部......