windows下利用python拨号电信3G并获得IP地址

import win32ras
import os
if __name__ == '__main__':
    params = ('USB-KEY DIAL',  '#777','','[email protected]', 'vnet.mobi','')
    fs, ret = win32ras.Dial(None, None, params, None)
    print ret
    if ret==0:
        print win32ras.GetConnectStatus(fs)
        data = os.popen("ipconfig", "r").readlines()
        have_ppp = 0
        ip_str = None
        for line in data:
             if line.find("USB-KEY DIAL")>=0:
                have_ppp = 1
             if have_ppp and line.strip().startswith("IP Address"):
                 ip_str = line.split(":")[1].strip()
                 have_ppp = 0
                 print ip_str

你可能感兴趣的:(windows,python,OS,电信)