首页 教程 正文
  • 本文约1070字,阅读需5分钟
  • 940
  • 22

Python Aws Ubuntu20 配置多IP

温馨提示:本文最后更新于2022年10月23日 01:39,若内容或图片失效,请在下方留言或联系博主。

1. 业务场景:

高频次交易需要多次访问接口,配置单服务器多IP绕过币安单个IP频率限制

2. AWS实例选择:

t3系列,东京A区,ubuntu20
这是我测试的币安延迟最低的配置(平均6ms)
换一个区域、一个系统,延迟变化可能会变大几百ms

Okx需要阿里云香港,B区,同理也可以配置多IP,不过网上的文档很多,也许下一篇我会写(平均8ms)

3. 配置AWS:

图片alt
图片alt
图片alt
图片alt
图片alt
图片alt
图片alt

4.配置服务器:

使用指令把新加的ip添加到网卡中:
172.31.34.174为分配的内部IP

ip addr add 172.31.34.174/20 dev ens5
echo 'ip addr add 172.31.34.174/20 dev ens5' >> /etc/rc.local
ip a

或者修改文件:
/etc/netplan/50-cloud-init.yaml
修改addresses 节点 把aws分配的内网ip写在 addresses节点下

ethernets:
    ens5:
        dhcp4: true
        dhcp6: false
        match:
            macaddress: 0a:5e:a8:b4:c3:5e
        set-name: ens5
        addresses:
           - 172.31.1.144/20
           - 172.31.0.140/20
version: 2

图片alt

修改完成后重启

5.Python使用多IP:

'''获取本地ip'''
import netifaces as ni
DuoIp = []
# print('检测服务器网络配置')
for dev in ni.interfaces():
    print('dev:',dev)
    if 'ens' in dev or 'eth' in dev or 'enp' in dev:
        if len(ni.ifaddresses(dev)) > 2:
            # print(ni.ifaddresses(dev))
            for i in ni.ifaddresses(dev)[2]:
                ip=i['addr']
                print(f"检测到私有ip:{ip}")
                if ip not in DuoIp:
                    DuoIp.append(ip)
print(f"当前服务器私有ip为{DuoIp}")

from requests_toolbelt.adapters import source  #指定出口IP
sb = requests.Session()
new_source = source.SourceAddressAdapter(DuoIp[1])
sb.mount('http://', new_source)
sb.mount('https://', new_source)

print(sb.get("http://ip-api.com/json"))
评论
更换验证码
$comment['poster']
Zgybkk
0
168.80.82.128 ChromeWindows 10
order losartan 25mg online - <a href="https://acephacrsa.com/">order cephalexin 125mg pills</a> keflex brand
约 13 小时前
回复
$comment['poster']
Cddszo
0
168.80.81.56 ChromeWindows 10
where can i buy cleocin - <a href="https://indometnp.com/">cheap indomethacin 75mg</a> order indomethacin 50mg generic
2024-10-16 06:48
回复
$comment['poster']
Eppmiy
0
163.198.212.40 ChromeWindows 10
amoxiclav order - <a href="https://baugipro.com/">augmentin 1000mg us</a> synthroid 75mcg generic
2024-10-13 09:42
回复
$comment['poster']
Ibozme
0
163.198.215.98 ChromeWindows nt
buy metronidazole 400mg pills - <a href="https://cenforcevs.com/">generic cenforce 100mg</a> cenforce order online
2024-10-09 02:29
回复
$comment['poster']
Nzvghf
0
163.198.215.187 ChromeWindows 10
where to buy betamethasone without a prescription - <a href="https://betnoson.com/awdifferin/">order differin without prescription</a> purchase benoquin online
2024-10-07 01:42
回复
$comment['poster']
Zurxau
0
163.198.215.187 ChromeWindows 10
permethrin brand - <a href="https://actizacs.com/tretinoin/">oral retin gel</a> buy tretinoin sale
2024-10-04 05:27
回复
$comment['poster']
Vqkcne
0
163.198.212.86 ChromeWindows nt
buy deltasone 5mg pills - <a href="https://apreplson.com/permethrin/">zovirax creams</a> buy elimite medication
2024-10-02 00:59
回复
$comment['poster']
Chybqb
0
168.80.83.195 ChromeWindows 10
oral isotretinoin 10mg - <a href="https://aisotane.com/">buy generic isotretinoin 10mg</a> order deltasone 40mg generic
2024-09-28 23:02
回复
$comment['poster']
Cwbfma
0
77.83.186.62 ChromeWindows 10
artane over the counter - <a href="https://voltapll.com/diclofenacgel/">diclofenac gel where to buy</a> emulgel online order
2024-09-23 05:38
回复
$comment['poster']
Pejlht
0
77.83.184.234 ChromeWindows nt
order periactin 4 mg online - <a href="https://periheptadn.com/aszanaflex/">order tizanidine generic</a> tizanidine price
2024-09-19 04:50
回复