Adding static routes on windows

If a Windows machine has 2 network cards on it, each on a separate network, 1 or more static routes is necessary to tell windows the correct network to use for a given packet.  On Windows XP static routes can be added with the route ADD command.

 

So if NIC1 was on the 192.168.1.0 with a gateway of 192.168.1.1 and NIC2 was on 192.168.10.0 with a gateway of 192.168.10.1 2 static routes would be needed:

 

route ADD 192.168.1.0 MASK 255.255.255.0 192.168.1.1 -p

route ADD 192.168.10.0 MASK 255.255.255.0 192.168.10.1 -p

 

The -p makes the routes persistent (e.g., will survive reboots).  This will direct any traffic destined for 192.168.1.* through NIC1 and traffic destined for 192.168.10.* through NIC2.

 

Without the static route windows will probably choose to send all traffic out the NIC with the highest (or lowest) MAC address.

 

Strongly typed WMI for .NET

Just discovered a way to use WMI via strongly typed objects.  mgmtclassgen.exe (comes with the .net SDK) will take a WMI schema object and generate a class with the object's classes and methods!

 

mgmtclassgen Win32_NetworkAdapter /P Win32_NetworkAdapter.cs 

 

creates a Win32_NetworkAdapter.cs file that contains a  Win32_NetworkAdapter class with all the properties and methods of the WMI object!

 

To find instances use Win32_NetworkAdapter.GetInstances("=").