Why would you want to do this? Let’s examine a scenario: You work in as a consultant that travels between offices. Some use DHCP, some don’t. One method that’s used in modern versions of Windows is the Alternate Configuration tab in the TCP/IP properties when DHCP addressing is selected. While that works well, it essentially limits the static address to a single address if a DHCP server isn’t found on the network. If you travel to networks with different static address schemes, that can be problematic.
Fortunately, the netsh command comes to the rescue! What needs to be done first is to create a file with the appropriate adapter, IP address, subnet mask, DNS server, etc. While you could create a file manually, you can also use the netsh command itself to export the configuration by using the following command:
netsh -c interface dump > c:\location1.netsh
This creates a file on the C: drive called location1.netsh. This is simply a text file with the current IP address information. You’d probably want to change location1 to something more appropriate. Also, since this is a text file, you can use the standard .txt extension, but by using .netsh instead, it makes it more obvious what that file actually is. (But, that’s really up to you.)
You can then manually modify this file in Notepad for each of the other locations. Or, you can make those changes manually in the TCP/IP properties of the network adapter and run the command again. The text file is pretty self-explanatory and shouldn’t be too hard to edit.
Once you have all the files for each of the locations, you can quickly import those settings via the –f parameter. An example of this command syntax is as follows:
netsh -f c:\location1.netsh
To go one step further, it wouldn’t be hard to simply copy and paste these commands into a batch file. So, you could create a file called ConnectLocation1.bat with the above command. Then, copy this to your desktop, Start Menu, or wherever you could readily access it. Now, a simple double-click would allow you to switch to that network.
Maybe that’s not exciting enough for you? In that case, let’s examine another feature of netsh: the diag ping feature. Yes, you can use the ping command by itself, but what netsh diag ping does is allow you to ping various IP options for an address, such as the default gateway or DNS servers. For example:
netsh diag ping dns
This pings the IP address of the DNS servers that have been configured, either manually or dynamically for all adapters. You can also specify a specific adapter by using the adapter parameter. For example:
netsh diag ping adapter 2
This command would ping all the IP addresses listed in the configuration for network adapter 2. Specifically, the default gateway, DNS servers, WINS servers (if configured) and the adapter’s own IP address. There are other items, such as the mail servers configured in a mail profile that can be pinged as well.
Still not impressed? There is one more very nice netsh diag command parameter:
netsh diag gui
This starts a GUI-based report of IP configuration settings.
Using Windows Vista? If so, the netsh has expanded its set of options. For example, most people who have used NetStumbler have noticed it doesn’t work under Vista. While programs like Vistumbler (http://www.techidiots.net/project-pages/vistumbler) provide the same functionality, the netsh command also has that ability. In a Windows Vista command prompt type:
netsh wlan show networks mode=bssid
This shows any SSID networks out there, including encryption used. It’s a command-line version of Netstumbler or Vistumbler. Not surprisingly, netsh wlan also allows for configuration of wireless network adapters.
One more netsh feature is the ability to configure the Windows firewall. Rather than try to list all of the firewall options, I’ll simply point to the very good WindowsNetworking.com article:
Hopefully, with this information, you can see just how useful this command can be! And we’ve just scratched the surface of what this command can do.