Get factory multiple C-segment (for example, Lenovo)

Source: Internet
Author: User
Tags nslookup nslookup command lenovo

Write the domain name in the Domains.txt file. (Collect the factory's level two domain name)

Result is the C segment of all URLs in the query domains.txt.

Result2.txt is the result.txt to remove the heavy filter.


Github:https://github.com/lufeirider/cscan


The following is the result of the Lenovo C segment

223.202.25.1-223.202.25.254124.127.169.1-124.127.169.25423.47.143.1-23.47.143.25464.26.251.1-64.26.251.25423.42.178.1-23.4 2.178.254223.202.19.1-223.202.19.254199.119.127.1-199.119.127.254219.142.122.1-219.142.122.254205.216.62.1-205.216.62.254 66.147.244.1-66.147.244.25412.130.131.1-12.130.131.254121.199.167.1-121.199.167.254103.30.232.1-103.30.232.254182.118.84.1 -182.118.84.254223.203.219.1-223.203.219.25464.88.179.1-64.88.179.254209.167.231.1-209.167.231.254208.74.204.1-208.74.204 .25469.168.101.1-69.168.101.25469.168.97.1-69.168.97.254106.37.234.1-106.37.234.254115.29.16.1-115.29.16.254203.196.120.1 -203.196.120.25458.247.171.1-58.247.171.25454.215.241.1-54.215.241.254208.115.47.1-208.115.47.254211.100.14.1-211.100.14. 254202.96.27.1-202.96.27.254219.141.216.1-219.141.216.25412.11.224.1-12.11.224.25466.117.30.1-66.117.30.254223.202.27.1-2 23.202.27.254114.113.233.1-114.113.233.254198.7.31.1-198.7.31.25459.61.88.1-59.61.88.254123.127.211.1-123.127.211.25458.2 0.164.1-58.20.164.25458.20.132.1-58.20.132.254139.219.9.1-139.219.9.254222.73.233.1-222.73.233.254223.202.62.1-223.202.62.254123.125.148.1-123.125.148. 254202.85.217.1-202.85.217.254121.199.251.1-121.199.251.254121.199.24.1-121.199.24.254223.203.218.1-223.203.218.25442.121 .0.1-42.121.0.25442.121.138.1-42.121.138.25466.192.69.1-66.192.69.25452.88.225.1-52.88.225.254162.216.170.1-162.216.170.2 54194.168.19.1-194.168.19.25467.222.128.1-67.222.128.25410.38.64.1-10.38.64.25450.19.223.1-50.19.223.254123.159.202.1-123 .159.202.25466.161.21.1-66.161.21.25410.96.160.1-10.96.160.25469.4.236.1-69.4.236.25469.7.171.1-69.7.171.25495.154.206.1 -95.154.206.25450.57.139.1-50.57.139.25423.53.201.1-23.53.201.25423.253.122.1-23.253.122.254210.51.191.1-210.51.191.25454 .231.0.1-54.231.0.254114.247.140.1-114.247.140.254123.103.15.1-123.103.15.254117.104.161.1-117.104.161.254202.107.203.1-2 02.107.203.254103.30.235.1-103.30.235.25454.183.218.1-54.183.218.254211.100.36.1-211.100.36.25442.121.254.1-42.121.254.25 4123.150.177.1-123.150.177.25410.96.144.1-10.96.144.25423.10.2.1-23.10.2.25443.255.224.1-43.255.224.254184.26.200.1-184.26.200.254104.98.45.1-104.98.45.25 454.227.254.1-54.227.254.25466.172.15.1-66.172.15.254117.104.160.1-117.104.160.254162.243.138.1-162.243.138.254103.244.58 .1-103.244.58.25410.96.0.1-10.96.0.25470.32.76.1-70.32.76.25459.120.128.1-59.120.128.25412.130.158.1-12.130.158.254116.21 3.92.1-116.213.92.254
#coding: Gb2312import osimport reimport queueimport threadingq=queue.queue () class  getcsgement:     #初始化     def __init__ (self,url):         if  "http"  in url:             pattern = re.compile (R ' (? <=//). + (? <!/) ')              match = pattern.search (URL)              try:                 url = match.group ()              except:                 print  "Regular Error"              self.url = url        else:             self.url = url             def csgment (self):        lookstr =  Self.nslookup (Self.url)         listip = self.fetip (LOOKSTR)                 if len ( Listip) ==0:            return  "Networkbad" &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;IF&NBSP;SELF.CHECKCDN ( Listip):            strip =  ""              for i in listIp:                 strIp = strIp + i +  ","              return strIp[:-1] +    ( may have used CDN) "                 Return self.makecseg (Listip)             # Querying with the nsLookUp command     def nslookup (self,url):          cmd =  ' nslookup %s 8.8.8.8 '  % url         handle = os.popen (cmd ,  ' R ')          result = handle.read ()         return result          #获取nslookup命令查询的结果里面的ip     def fetip (self, Result):    &nbsP;    ips =  re.findall (R ' (?1:             return True        return  false         #生成c段     def makecseg (self,ips): &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;IF&NBSP;NOT&NBSP;SELF.CHECKCDN (IPs):             ipStr =  "". Join (IPS)              end = ipstr.rfind (".")              return ipStr[0:end+1]  +  "1-"  + ipStr[0:end+1] +  "254" #开始扫描          Def scaner ():     while not q.empty ():         url=q.get ()       &Nbsp; t = getcsgement (URL)         result =  T.csgment ()                 if  not  "Networkbad"  in result:             print url +  ":"  + result             if not  "CDN"  in result:                 writefile ("Result.txt", result +  "\\\\n")         else:             t = getcsgement (URL)              result2 = t.csgment ()              if not "Networkbad"  in result2:                 print url +  ":"  + result2                 if not  "CDN"  in result2:                      writefile ("Result.txt", result2 +  "\\\\n")              else:                 print url +  ": Cannot access   or   network instability"                      if q.empty ():         delrep ()                   #保存记录def  writefile (filename,context):     f= file (filename, "A +")     f.write (context)     f.close () #去重复def  delrep ():     buff = []    for ln in open (' Result.txt '):         if ln in buff:             continue        buff.append (LN)     with open (' Result2.txt ',  ' W ')  as handle:         handle.writelines (Buff)                   #判断文件是否创建def  isexist ():    if not  Os.path.exists (R ' Result.txt '):         f = open (' Result.txt ',   ' W ')     &nbsP;   f.close ()     else:         Os.remove (' Result.txt ')             if  Os.path.exists (R ' result2.txt '):         os.remove (' result2.txt ')      if __name__== "__main__":     isexist ()           #读取网址     lines = open ("Domains.txt", "R")      for line in lines:        line=line.rstrip ()         q.put (line)               #开启线程     for i in range (3):          t = threading. Thread (Target=scaner)         t.start ()


This article is from "Lu Fei" blog, please be sure to keep this source http://llufei.blog.51cto.com/11390668/1758606

Get factory multiple C-segment (for example, Lenovo)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.