美文网首页
使用Python获取Dropbox的IP地址

使用Python获取Dropbox的IP地址

作者: Vaayne | 来源:发表于2015-07-14 19:37 被阅读381次

    使用更改hosts时需要有可用的ip地址,但是网上的好多地址都过期了,所以需要自己去获取当时有用的地址。
    下面是代码:(python3)

    #!/usr/bin/python
    # -*- coding: utf-8 -*-  
    
    def GetLists(subdomain,start,end):
        ret = []
        for i in xrange(int(start),int(end)+1):
            ret.append(subdomain+str(i)+'.dropbox.com')
        return ret
    
    def GetDlClientLists():
        return GetLists('dl-client',1,999)
    
    def GetDlDebugLists():
        return GetLists('dl-debug',1,40)
    
    def GetClientLists():
        return GetLists('client',1,99)
    
    def GetNotifyLists():
        return GetLists('notify',1,10)
    
    hosts = []
    hosts.extend([
            'dropbox.com',
            'www.dropbox.com',
            'forums.dropbox.com',
            'dl.dropboxusercontent.com',
            'd.dropbox.com',
            'client-lb.dropbox.com'
            ])
    hosts.extend(GetDlClientLists())
    hosts.extend(GetDlDebugLists())
    hosts.extend(GetClientLists())
    hosts.extend(GetNotifyLists())
    
    import subprocess
    for h in hosts:
        cmd = 'nslookup -vc ' + h + ' 8.8.8.8'
        p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    
        valid = False
        for line in p.stdout.readlines():
            if line.startswith('Non-authoritative answer:'):
                valid = True
            elif valid and line.startswith('Address:'):
                ip = line.replace('Address: ','').replace('\n','')
                print ip + ' ' + h
                with open('ip.txt', 'a+') as f:
                    f.write(ip + ' ' + h + '\n')
    
    

    下面是部分结果:

    108.160.172.232 dropbox.com
    108.160.172.200 dropbox.com
    108.160.172.206 www.dropbox.com
    108.160.172.238 www.dropbox.com
    54.230.108.94 forums.dropbox.com
    54.230.108.47 forums.dropbox.com
    54.230.108.131 forums.dropbox.com
    54.230.108.80 forums.dropbox.com
    54.230.108.22 forums.dropbox.com
    54.230.108.45 forums.dropbox.com
    54.230.108.13 forums.dropbox.com
    54.230.108.122 forums.dropbox.com
    50.16.243.219 dl.dropboxusercontent.com
    204.236.226.117 dl.dropboxusercontent.com
    23.21.69.48 dl.dropboxusercontent.com
    23.23.121.189 dl.dropboxusercontent.com
    23.23.237.190 dl.dropboxusercontent.com
    23.21.60.91 dl.dropboxusercontent.com
    54.221.222.114 dl.dropboxusercontent.com
    54.243.243.165 dl.dropboxusercontent.com
    108.160.172.193 d.dropbox.com
    108.160.172.225 d.dropbox.com
    

    使用这些地址就可以上dropbox了。


    微信公众号:lyishaou


    微信公众号

    相关文章

      网友评论

          本文标题: 使用Python获取Dropbox的IP地址

          本文链接:https://www.haomeiwen.com/subject/hsguqttx.html