使用Python獲取Dropbox的IP地址

使用更改hosts時(shí)需要有可用的ip地址,但是網(wǎng)上的好多地址都過期了,所以需要自己去獲取當(dāng)時(shí)有用的地址。
下面是代碼:(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')

下面是部分結(jié)果:

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


微信公眾號
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容

  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 134,991評論 19 139
  • Ubuntu的發(fā)音 Ubuntu,源于非洲祖魯人和科薩人的語言,發(fā)作 oo-boon-too 的音。了解發(fā)音是有意...
    螢火蟲de夢閱讀 99,593評論 9 467
  • 1.這篇文章不是本人原創(chuàng)的,只是個(gè)人為了對這部分知識做一個(gè)整理和系統(tǒng)的輸出而編輯成的,在此鄭重地向本文所引用文章的...
    SOMCENT閱讀 13,136評論 6 174
  • 簡介 用簡單的話來定義tcpdump,就是:dump the traffic on a network,根據(jù)使用者...
    保川閱讀 5,990評論 1 13
  • 星期天下午是個(gè)魔咒 教人分離,不舍也分離 陽光里都透著冷氣 時(shí)間遞給我你的袖口 也遞給我一張火車票 安檢門后還在找...
    麻球麻麻閱讀 235評論 0 2