Change Gateway Programmatically

Tim Golden tim.golden at viacom-outdoor.co.uk
Wed Jan 11 03:41:09 EST 2006


[Godwin Burby]
| Subject: Re: Change Gateway Programmatically
| 
| Well netsh turned out to be the perfect solution for my problem(even
| though doing it in python would have given me some kicks).

Just in case you fancied an alternative approach, you can do
this with WMI.

(untested, because I don't want to mess up my gateway)
<code>
import wmi

c = wmi.WMI ()
nic = c.Win32_NetworkAdapterConfiguration (IPEnabled=True)[0]
print nic.DefaultIPGateway, nic.GatewayCostMetric
nic.SetGateways (DefaultIPGateway=["aaa.bbb.ccc.ddd"],
GatewayCostMetric=["20"])
</code>

TJG

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________



More information about the Python-list mailing list