C#????IP????????y?????????
???????????? ???????[ 2015/6/17 15:00:10 ] ???????????????
????2 ????IP???????
/// <summary>
/// ????DHCP????
/// </summary>
public void EnableDHCP()
{
ManagementClass wmi = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc = wmi.GetInstances();
foreach (ManagementObject mo in moc)
{
if (!(bool)mo["IPEnabled"])
continue;
if (mo["SettingID"].ToString() == this.NetworkInterfaceID) //???????????????? ????????????????IP???
{
mo.InvokeMethod("SetDNSServerSearchOrder"?? null);
mo.InvokeMethod("EnableDHCP"?? null);
}
}
??????
????3. ?????????????
public class NetworkAdapterUtil
{
/// <summary>
/// ??????????????????????????????????????
/// </summary>
/// <returns></returns>
public List<NetworkAdapter> GetAllNetworkAdapters() //???????????????????????
{
IEnumerable<NetworkInterface> adapters = NetworkInterface.GetAllNetworkInterfaces(); //?????????????
return GetNetworkAdapters(adapters);
}
/// <summary>
/// ???????????IP????????
/// </summary>
/// <param name="adapters">????????????</param>
/// <param name="adapterTypes">?????????????磬UP??DOWN??</param>
/// <returns></returns>
private List<NetworkAdapter> GetNetworkAdapters(IEnumerable<NetworkInterface> adapters?? params NetworkInterfaceType[] networkInterfaceTypes)
{
adapterList = new List<NetworkAdapter>();
foreach (NetworkInterface adapter in adapters)
{
if (networkInterfaceTypes.Length <=0) //??????????????????????
{
if (adapter != null)
{
NetworkAdapter adp = SetNetworkAdapterValue(adapter);
adapterList.Add(adp);
}
else
{
return null;
}
}
else //??????????
{
foreach (NetworkInterfaceType networkInterfaceType in networkInterfaceTypes)
{
if (adapter.NetworkInterfaceType.ToString().Equals(networkInterfaceType.ToString()))
{
adapterList.Add(SetNetworkAdapterValue(adapter));
break; //?????????
}
}
}
}
return adapterList;
??
/// <summary>
/// ?????????????????
/// </summary>
/// <param name="adapter"></param>
/// <returns></returns>
private NetworkAdapter SetNetworkAdapterValue(NetworkInterface adapter)
{
NetworkAdapter networkAdapter = new NetworkAdapter();
IPInterfaceProperties ips = adapter.GetIPProperties();
networkAdapter.Description = adapter.Name;
networkAdapter.NetworkInterfaceType = adapter.NetworkInterfaceType.ToString();
networkAdapter.Speed = adapter.Speed / 1000 / 1000 + "MB"; //???
networkAdapter.MacAddress = adapter.GetPhysicalAddress(); //??????????
networkAdapter.NetworkInterfaceID = adapter.Id;//???????????????
networkAdapter.Getwaryes = ips.GatewayAddresses; //??????????
networkAdapter.IPAddresses = ips.UnicastAddresses; //IP???????
networkAdapter.DhcpServerAddresses = ips.DhcpServerAddresses;//DHCP???????
networkAdapter.IsDhcpEnabled =ips.GetIPv4Properties()==null?false: ips.GetIPv4Properties().IsDhcpEnabled; //???????DHCP????
IPInterfaceProperties adapterProperties = adapter.GetIPProperties();//???IPInterfaceProperties???
networkAdapter.DnsAddresses = adapterProperties.DnsAddresses; //????????DNS??????IP?????? ????
return networkAdapter;
}
}
??
????4 ????? ??????????????
/// <summary>
/// ??????????????
/// </summary>
/// <returns></returns>
public void EnableAllAdapters()
{
// ManagementClass wmi = new ManagementClass("Win32_NetworkAdapter");
// ManagementObjectCollection moc = wmi.GetInstances();
System.Management.ManagementObjectSearcher moc = new System.Management.ManagementObjectSearcher("Select * from Win32_NetworkAdapter where NetEnabled!=null ");
foreach (System.Management.ManagementObject mo in moc.Get())
{
//if (!(bool)mo["NetEnabled"])
// continue;
string capation = mo["Caption"].ToString();
string descrption =mo["Description"].ToString();
mo.InvokeMethod("Enable"??null);
}
}
/// <summary>
/// ??????????????
/// </summary>
public void DisableAllAdapters()
{
// ManagementClass wmi = new ManagementClass("Win32_NetworkAdapter");
// ManagementObjectCollection moc = wmi.GetInstances();
System.Management.ManagementObjectSearcher moc = new System.Management.ManagementObjectSearcher("Select * from Win32_NetworkAdapter where NetEnabled!=null ");
foreach (System.Management.ManagementObject mo in moc.Get())
{
//if ((bool)mo["NetEnabled"])
// continue;
string capation = mo["Caption"].ToString();
string descrption = mo["Description"].ToString();
mo.InvokeMethod("Disable"?? null);
}
}
???????????????????????漰???????????????????SPASVOС??(021-61079698-8054)?????????????????????????
??????
???????C#?е?StringC# Socket???????????????????C#?????????????????????????C#???????C#????????????Log4net??????δ????C#?????????????C#?????????????????C#???????????????C#????????????????C#7 ?е?Tuple??????C#??TypeScript - GeneratorC# ?????????細(xì)??????????C#?е???н???C#??MySQL?????????μ??Ч?????д??C#????C++??dll???C#??VS2010????е??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11????????
?????????App Bug???????????????????????Jmeter?????????QC??????APP????????????????app?????е????????jenkins+testng+ant+webdriver??????????????JMeter????HTTP???????Selenium 2.0 WebDriver ??????