"kode4u" <[EMAIL PROTECTED]> wrote: > How to use python get my windows box's ip setting type? Dynamic ip, or > static ip? > > If it's static ip, what's the exact value? > Here's one way:
def ipinfo(interface="Local Area Connection"): dhcpenabled = False staticip = None subnetmask = None for l in os.popen('netsh interface ip show address "%s"' % interface): l = l.strip() if l.startswith('DHCP enabled'): dhcpenabled = l.endswith('Yes') if l.startswith("IP Address"): staticip = l.rsplit(None,1)[-1] if l.startswith("SubnetMask"): subnetmask = l.rsplit(None,1)[-1] return dhcpenabled, staticip, subnetmask >>> ipinfo() (True, None, None) >>> ipinfo("VMware Network Adapter VMnet1") (False, '192.168.126.1', '255.255.255.0') -- http://mail.python.org/mailman/listinfo/python-list