I created NetProfiles because there was no good way to manage multiple IP profiles within Windows. As a network engineer, I travel to multiple client sites - each having unique IP settings. NetProfiles allows users to setup multiple profiles to automate this process.
In this article, I will demonstrate several techniques:
NetProfiles relies on the .NET Framework version 2.0.
I have included the compiled binary (x86) and the Visual Studio project (VS2008).
//Connect to the registry and create the Keys necessary for
//NetProfiles
//
RegistryKey cUser = Registry.LocalMachine;
cUser = cUser.OpenSubKey("SOFTWARE",true);
cUser.CreateSubKey("AntiDesign\\NetProfiles\\__Adapters");
cUser = cUser.OpenSubKey("AntiDesign\\NetProfiles\\__Adapters",true);
//create keys for all network adapters
//
//
for (int i = 0; i < cboSelectAdapter.Items.Count; i++)
{
//create subkeys for each network adapter found
cUser.CreateSubKey(cboSelectAdapter.Items[i].ToString());
RegistryKey tmp = cUser.OpenSubKey(cboSelectAdapter.Items[i].ToString(), true);
//set default values inside the created keys
tmp.SetValue("CurrentProfile", "");
tmp.SetValue("RouteNetwork", "");
}
//Function to populate combo box with a list of network adapters
//
//
private void loadAdapters()
{
foreach (NetworkInterface netInterface in
NetworkInterface.GetAllNetworkInterfaces())
{
// Only get ethernet and wireless adapters
if (netInterface.NetworkInterfaceType == NetworkInterfaceType.Ethernet |
netInterface.NetworkInterfaceType == NetworkInterfaceType.Wireless80211)
{
cboSelectAdapter.Items.Add(netInterface.Name);//add to list
}
}
try
{
cboSelectAdapter.SelectedIndex = 0;
}
catch { }
}
//build the argument strings for netsh.exe
//
//
string args, argsDNS;
args = "interface ip set address name=\"" + AdapterName + "\" static " +
ipAddress + " " + subnetMask + " " + gateway + " 1";
argsDNS = "interface ip set dns name=\"" + AdapterName + "\" static " +
dnsServer;
//apply the changes using netsh
//
//
Process netsh = new Process();
netsh.StartInfo.FileName = "netsh.exe";
netsh.StartInfo.UseShellExecute = false;
netsh.StartInfo.CreateNoWindow = true;
netsh.StartInfo.Arguments = args;
netsh.Start();
netsh.WaitForExit();
//Add the dns server
//
//
netsh.StartInfo.Arguments = argsDNS;
netsh.Start();
netsh.WaitForExit();
netsh.Dispose();
//add the static route
//
//
Process cmd = new Process();
cmd.StartInfo.FileName = "route.exe";
cmd.StartInfo.Arguments = "add " + routeNetwork + " mask " +
routeMask + " " + routeGateway + " metric " + routeMetric;
cmd.StartInfo.UseShellExecute = false;
cmd.StartInfo.CreateNoWindow = true;
cmd.Start();
cmd.WaitForExit();
cmd.Dispose();
This app is relatively lightweight, and provides useful functionality that is not provided by Windows.
| You must Sign In to use this message board. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||