本文整理汇总了C#中System.Net.NetworkInformation.NetworkInterface.GetIPProperties方法的典型用法代码示例。如果您正苦于以下问题:C# NetworkInterface.GetIPProperties方法的具体用法?C# NetworkInterface.GetIPProperties怎么用?C# NetworkInterface.GetIPProperties使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.NetworkInformation.NetworkInterface
的用法示例。
在下文中一共展示了NetworkInterface.GetIPProperties方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NetInterface
public NetInterface(NetworkInterface adapterIn)
{
// set up the adapter
adapter = adapterIn;
stats = adapter.GetIPv4Statistics();
// set up the logging
logPath = Path.Combine("logs", Path.Combine(adapter.Description, adapter.GetPhysicalAddress().ToString(), adapter.Id));
logHandler = new LogHandler(logPath);
loadDataInstant(DateTime.UtcNow.Ticks);
// set up the data tracking
dataTransferStart = currentTicks();
bytesInSession = stats.BytesReceived;
bytesOutSession = stats.BytesSent;
properties = adapter.GetIPProperties();
//Console.WriteLine(adapter.Name + " " + adapter.Description + " " + adapter.OperationalStatus);
Tracker = new Tracker(logHandler);
}
示例2: IfMtu
/// <summary>
/// Initializes a new instance of the <see cref="IfMtu"/> class.
/// </summary>
/// <param name="index">The index.</param>
/// <param name="networkInterface">The network interface.</param>
public IfMtu(int index, NetworkInterface networkInterface)
: base("1.3.6.1.2.1.2.2.1.4.{0}", index)
{
if (networkInterface.Supports(NetworkInterfaceComponent.IPv4))
{
var pv4InterfaceProperties = networkInterface.GetIPProperties().GetIPv4Properties();
_data = new Integer32(pv4InterfaceProperties == null ? -1 : pv4InterfaceProperties.Mtu);
}
else
{
_data = new Integer32(networkInterface.GetIPProperties().GetIPv6Properties().Mtu);
}
}
示例3: NetworkInterface
internal NetworkInterface(NetworkInterfaceInformation info)
{
Information = info;
IPv4Index = -1;
IPv6Index = -1;
if (info.Supports(NetworkInterfaceComponent.IPv4))
{
IPv4Index = info.GetIPProperties().GetIPv4Properties().Index;
}
if (info.Supports(NetworkInterfaceComponent.IPv6))
{
IPv6Index = info.GetIPProperties().GetIPv6Properties().Index;
}
Index = Interlocked.Increment(ref NextIndex);
}
示例4: GetNetworkInterfaceInfo
public static NetworkInterfaceInfo GetNetworkInterfaceInfo (NetworkInterface networkInterface)
{
if (networkInterface == null) {
return new NetworkInterfaceInfo (IPAddress.Any, 0);
}
var properties = networkInterface.GetIPProperties ();
var ipv4_properties = properties.GetIPv4Properties ();
if (ipv4_properties == null) {
throw new ArgumentException ("The specified network interface does not support IPv4.", "networkInterface");
}
var host_name = Dns.GetHostName ();
foreach (var address in properties.UnicastAddresses)
{
string addressHostname = null;
try
{
addressHostname = Dns.GetHostEntry(address.Address).HostName;
}
catch(SocketException)
{
}
if (address.Address.AddressFamily == AddressFamily.InterNetwork && addressHostname == host_name) {
return new NetworkInterfaceInfo (address.Address, ipv4_properties.Index);
}
}
throw new ArgumentException (string.Format (
"The specified network interface does not have a suitable address for the local hostname: {0}.", host_name), "networkInterface");
}
示例5: getSentPackets
public long getSentPackets( NetworkInterface conn )
{
IPInterfaceProperties properties = conn.GetIPProperties();
IPv4InterfaceStatistics ipstat = conn.GetIPv4Statistics();
return ipstat.BytesSent;
}
示例6: getReceivedTraffic
/*
* Get received traffic
* returns String[] array
*/
public long getReceivedTraffic( NetworkInterface conn )
{
IPInterfaceProperties properties = conn.GetIPProperties();
IPv4InterfaceStatistics ipstat = conn.GetIPv4Statistics();
return ipstat.BytesReceived;
}
示例7: GetUpdateType
public static UpdateType GetUpdateType(NetworkInterface oldInterface, NetworkInterface newInterface)
{
if (oldInterface.Id != newInterface.Id)
return UpdateType.Name;
IPInterfaceProperties oldIPProps = oldInterface.GetIPProperties();
IPInterfaceProperties newIPProps = newInterface.GetIPProperties();
if (HasIPChanged(oldIPProps, newIPProps))
return UpdateType.IP;
if (HasNetmaskChanged(oldIPProps, newIPProps))
return UpdateType.Netmask;
if (HasGatewayChanged(oldIPProps, newIPProps))
return UpdateType.Gateway;
if (HasDHCPChanged(oldIPProps, newIPProps))
return UpdateType.DHCP;
if (HasDNSChanged(oldIPProps, newIPProps))
return UpdateType.DNS;
if (!oldIPProps.Equals(newIPProps))
return UpdateType.Other;
return UpdateType.None;
}
示例8: GetGatewayAddressFromNetInterface
public static IPAddress GetGatewayAddressFromNetInterface(NetworkInterface intf)
{
IPInterfaceProperties ipProps = intf.GetIPProperties();
if (ipProps == null)
return IPAddress.Any;
if (ipProps.GatewayAddresses == null || ipProps.GatewayAddresses.Count == 0)
return IPAddress.Any;
return ipProps.GatewayAddresses[0].Address;
}
示例9: isNetworkConnected
public Boolean isNetworkConnected(NetworkInterface net)
{
Boolean bReturn = false;
if (net != null && net.OperationalStatus == OperationalStatus.Up && net.GetIPProperties() != null && net.Description != null && net.NetworkInterfaceType != NetworkInterfaceType.Loopback) {
bReturn = true;
}
Helper.doLog("isNetworkConnected " + net.Id + " = " + bReturn, Properties.Settings.Default.DebugMode);
return bReturn;
}
示例10: SetSocketOptionsForNic
private void SetSocketOptionsForNic(NetworkInterface nic)
{
nic.GetIPProperties()
.UnicastAddresses
.Where(unicast => unicast.Address.AddressFamily == AddressFamily.InterNetwork)
.ToList()
.ForEach(
address =>
socket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership,
new MulticastOption(IPAddress.Parse(AllHostsMulticastIP), address.Address)));
}
示例11: NetworkConfigModel
public NetworkConfigModel(NetworkInterface ni)
{
var ip = ni.GetIPProperties();
this.IpAddress = ip.UnicastAddresses.Count > 0 ? ip.UnicastAddresses[0].Address.ToString() : "";
this.Gateway = ip.GatewayAddresses.Count > 0 ? ip.GatewayAddresses[0].Address.ToString() : "";
this.Subnet = ip.UnicastAddresses.Count > 0 ? ip.UnicastAddresses[0].IPv4Mask.ToString() : "";
this.DNSList = ip.DnsAddresses.Count > 0 ? string.Join(";", ip.DnsAddresses.Select(dn => dn.ToString())) : "";
this.NetworkName = ni.Name;
this.InterfaceName = ni.Description;
this.UseDHCP = string.IsNullOrEmpty(this.IpAddress) && string.IsNullOrEmpty(this.Gateway);
}
示例12: AddRoute
/// <summary>
/// Returns the destination IP we'll later want to delete
/// </summary>
/// <param name="adapter"></param>
/// <param name="hostOrIp"></param>
/// <returns></returns>
public static string AddRoute(NetworkInterface adapter, string hostOrIp )
{
IPAddress remoteAddress = null;
if (IPAddress.TryParse(hostOrIp, out remoteAddress)) {
// already an IP address
} else {
// resolve it
try
{
IPAddress[] addresslist = Dns.GetHostAddresses(hostOrIp);
if (addresslist.Length == 0)
{
MessageBox.Show("Can't resolve " + hostOrIp);
}
else
{
remoteAddress = addresslist[0];
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error");
return null;
}
}
IPInterfaceProperties properties = adapter.GetIPProperties();
try
{
if (remoteAddress != null)
{
GatewayIPAddressInformationCollection gateways = properties.GatewayAddresses;
for (int j = 0; j < gateways.Count; j++)
{
GatewayIPAddressInformation gateway = gateways[j];
// Add the route entry to the route table to solve the Windows XP issue.
AddRoute(gateway.Address.ToString(), remoteAddress.ToString());
}
}
}
catch (Exception ex)
{
//DebugEx.WriteException(ex);
MessageBox.Show(ex.Message, "Error");
return null;
}
return remoteAddress.ToString();
}
示例13: GetIpv4StringFromNetworkAdapter
private static string GetIpv4StringFromNetworkAdapter(string result, NetworkInterface adapter)
{
if (adapter == null) return null;
foreach (UnicastIPAddressInformation ip in adapter.GetIPProperties().UnicastAddresses)
{
if (ip.Address.AddressFamily == AddressFamily.InterNetwork)
{
result = ip.Address.ToString();
}
}
return result;
}
示例14: GetGatewayAddress
public static IPAddress GetGatewayAddress(NetworkInterface iface)
{
if (iface == null)
return IPAddress.Parse(BadIP);
IPInterfaceProperties ipProperties = iface.GetIPProperties();
foreach (GatewayIPAddressInformation ip in ipProperties.GatewayAddresses)
if (ip.Address.AddressFamily == AddressFamily.InterNetwork)
return ip.Address;
return IPAddress.Parse(BadIP);
}
示例15: GetDNSAddress
public static IPAddress GetDNSAddress(NetworkInterface iface)
{
if (iface == null)
return IPAddress.Parse(BadIP);
IPInterfaceProperties ipProperties = iface.GetIPProperties();
foreach (IPAddress ip in ipProperties.DnsAddresses)
if (ip.AddressFamily == AddressFamily.InterNetwork)
return ip;
return IPAddress.Parse(BadIP);
}