من یه سرچی تو گوگل زدم این کدو پیدا کردم . دوستان تست کنید تو همین تاپیک بگین جواب میده یانه!
من خودم تازه ویندوز عوض کردم هنوز ویژ<ال رو نصب نکردم میخام اگه کده جواب میده تا نصب کنم.
کد :
[CODERegistryKey key = Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentC ontrolSet\\Services\\Tcpip\\Parameters\\Interfaces ", true);
// Registry key where IP information is stored.
foreach (string s in key.GetSubKeyNames())
{
RegistryKey rk = Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentC ontrolSet\\Services\\Tcpip\\Parameters\\Interfaces \\" + s, true);
if (rk.ValueCount >= 12) // In general, active network card will have more than 12 setting values
{
try
{
string[] s1 = { "12.24.36.48", "13.26.39.64" }; // Array of IP addresses to set.
rk.SetValue("IPAddress", s1);
}
catch (Exception exc)
{
// Error message logic here.
}
}
rk.Close();
}
][/CODE]
اینم کد دیگه ای که تو سایت دیگه ای بود
public void setIP(string ip_address, string subnet_mask)
{
ManagementClass objMC = new ManagementClass("Win32_NetworkAdapterConfiguration ");
ManagementObjectCollection objMOC = objMC.GetInstances();
foreach (ManagementObject objMO in objMOC)
{
if ((bool)objMO["IPEnabled"])
{
try
{
ManagementBaseObject setIP;
ManagementBaseObject newIP =
objMO.GetMethodParameters("EnableStatic");
newIP["IPAddress"] = new string[] { ip_address };
newIP["SubnetMask"] = new string[] { subnet_mask };
setIP = objMO.InvokeMethod("EnableStatic", newIP, null);
}
catch (Exception)
{
throw;
}
}
}
}