利用fabric获取拨号服务器代理

代理服务器上的web服务没搭建成功,只能采用这种方式了

使用示例

import re
from fabric import Connection

def main():
    c = Connection("用户名@ip", port=0, connect_kwargs={"password": ""})
    ip = re.findall(r'\d+\.\d+\.\d+\.\d+', str(c.run("ifconfig")))[5]
    print(ip)
    c.close()

if __name__ == '__main__':
    main()

输出内容

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.99.148 netmask 255.255.255.0 broadcast 192.168.99.255
inet6 fe80::215:5dff:fe0a:5c72 prefixlen 64 scopeid 0x20
ether 00:15:5d:0a:5c:72 txqueuelen 1000 (Ethernet)
RX packets 15537451 bytes 4663930804 (4.3 GiB)
RX errors 0 dropped 70833 overruns 0 frame 0
TX packets 7816569 bytes 3530126546 (3.2 GiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10
loop txqueuelen 0 (Local Loopback)
RX packets 3710 bytes 368837 (360.1 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 3710 bytes 368837 (360.1 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

ppp0: flags=4305<UP,POINTOPOINT,RUNNING,NOARP,MULTICAST> mtu 1492
inet 121.239.127.24 netmask 255.255.255.255 destination 121.239.127.1
ppp txqueuelen 3 (Point-to-Point Protocol)
RX packets 23405 bytes 10003878 (9.5 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 26396 bytes 10117083 (9.6 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

121.239.127.24