• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >python > Python实现获取域名所用服务器的真实IP

Python实现获取域名所用服务器的真实IP

作者:hebedich 字体:[增加 减小] 来源:互联网

hebedich 通过本文主要向大家介绍了网络单元所用域名,python 取url的域名,python 域名解析,python作为服务器,python web服务器等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

本来是要写个程序用的,没写完不写了,这一部分就贴出来吧

验证域名和IP

class JianKong():
  '''查询IDC信息,封ip和过白名单'''
  def __init__(self):
    pass
  @classmethod
  def ip_verify(cls,str):
    '验证IP地址规范'
    pattern=re.compile('(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])')
    s=pattern.findall(str)
    if len(s)>0:
      ip=s[0][0]+'.'+s[0][1]+'.'+s[0][2]+'.'+s[0][3]
      return ip
    else:
      print 'IP格式不正确'#弹窗提醒
      return ''
  @classmethod
  def domain_verify(cls,domainStr):
    '验证域名规范,返回合法域名列表'
    domainList=[]
    file=open('c:\domain.txt','r')
    domainType=file.readlines()
    #去重
    domainType=list(set(domainType))
    #print domainType
    file.close()
    #file=['com','ac','com.cn','net'+'']
    for line in domainType:
      #文件中动态读取每个顶级域名进行匹配
      line=line.strip()
      pattern=re.compile('([a-z0-9][a-z0-9\-]*?\.'+line+')(?:\s|$)+',re.S)
      #例如[a-z0-9][a-z0-9\-]*?\.com.cn(?:\s|$)+ 中(?:\s|$)表示域名后缀后面必须是空白符或者字符结束(?:)表示括号不用于分组功能
      #防止.com.cn先匹配到.com即停止匹配导致错误,或者匹配到.comc多了字符
      result=pattern.findall(domainStr)
      if len(result)>0:
        #正确结果添加到返回列表
        domainList=domainList+result
    #去重
    domainList=list(set(domainList))
    newList=[]
    for d in domainList:
      if d not in domainType and d+'\n' not in domainType:
        newList.append(d)
           
    return newList
  @classmethod
  def getDomainType(cls):
    '从工信部网站获取所有合法域名后缀'
    file=open('c:/domain.txt','w')
    p=re.compile('class=\"by2\">\.(.*?)\ </td>', re.S)
    for i in range(1,23):
      data='domainName=&domainBlur=0&page.pageSize=20&pageNo='+str(i)+'&jumpPageNo='+str(i)
      header={'Host':'www.miitbeian.gov.cn','Origin':'http://www.miitbeian.gov.cn','User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 UBrowser/5.5.6125.14 Safari/537.36','Referer':'http://www.miitbeian.gov.cn/basecode/query/queryDomain.action;jsessionid=HSTRWpLZbR0cX4vFkDpnpbNBYyRl4GwW1fxpyhdyc0fcfhkvJTBV!1139295987'}
      url='http://www.miitbeian.gov.cn/basecode/query/queryDomain.action;jsessionid=HSTRWpLZbR0cX4vFkDpnpbNBYyRl4GwW1fxpyhdyc0fcfhkvJTBV!1139295987'
      request=urllib2.Request(url,data,header)
      response=urllib2.urlopen(request)
      recv=response.read()
      s=p.findall(recv)
      #print s
      #去重
      s=list(set(s))
      for y in s:
        file.write(y+'\n')
        file.flush()
        #print str(i)+' '+y
    file.close()
    print '完毕'#弹窗完成
</div>

</div>

您可能想查找下面的文章:

  • Python实现获取域名所用服务器的真实IP
  • Python实现获取域名所用服务器的真实IP

相关文章

  • 深入理解NumPy简明教程---数组2
  • 零基础写python爬虫之打包生成exe文件
  • 浅谈python中的变量默认是什么类型
  • python3.5仿微软计算器程序
  • python模拟enum枚举类型的方法小结
  • python实现斐波那契递归函数的方法
  • python django集成cas验证系统
  • Python实现身份证号码解析
  • 使用Python操作Elasticsearch数据索引的教程
  • Python连接mysql数据库的正确姿势

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • 简单介绍Python下自己编写web框架的一些要点
    • python查看微信好友是否删除自己
    • Python将xml和xsl转换为html的方法
    • Python的标准模块包json详解
    • Python提取网页中超链接的方法
    • python计算对角线有理函数插值的方法
    • python网络编程学习笔记(四):域名系统
    • 在Python中使用SQLite的简单教程
    • python ElementTree 基本读操作示例
    • python获取一组数据里最大值max函数用法实例

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有