本文整理汇总了C#中System.Net.NetworkInformation.NetworkInterface类的典型用法代码示例。如果您正苦于以下问题:C# NetworkInterface类的具体用法?C# NetworkInterface怎么用?C# NetworkInterface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NetworkInterface类属于System.Net.NetworkInformation命名空间,在下文中一共展示了NetworkInterface类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Server
public Server (string defaultLocation, NetworkInterface networkInterface)
{
default_location = defaultLocation;
network_interface_info = NetworkInterfaceInfo.GetNetworkInterfaceInfo (networkInterface);
request_listener = new RequestListener (this);
announcers = new Dictionary<string, Announcer> ();
}
示例2: 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;
}
示例3: Client
public Client (NetworkInterface networkInterface)
{
network_interface_info = NetworkInterfaceInfo.GetNetworkInterfaceInfo (networkInterface);
service_cache = new ServiceCache (this);
notify_listener = new NotifyListener (this);
browsers = new Dictionary<string, Browser> ();
}
示例4: UnicastNetworkAddressInformation
/// <summary>
/// Creates a new unicast network address information instance.
/// </summary>
/// <param name="iface">The network interface.</param>
/// <param name="information">The address information.</param>
public UnicastNetworkAddressInformation(NetworkInterface iface, UnicastIPAddressInformation information)
: base(iface)
{
this.UnicastInformation = information;
this.Stale = false;
this.Selected = true;
}
示例5: 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");
}
示例6: Nic
private Nic(NetworkInterface ni)
{
_isInitializing = true;
Reload(ni);
_isInitializing = false;
ConnectivityCheckRequired(this);
}
示例7: getSentPackets
public long getSentPackets( NetworkInterface conn )
{
IPInterfaceProperties properties = conn.GetIPProperties();
IPv4InterfaceStatistics ipstat = conn.GetIPv4Statistics();
return ipstat.BytesSent;
}
示例8: ChatServer
public ChatServer(int portNumber, object networkInterface, string serverName)
{
this.serverName = serverName;
this.portNumber = portNumber;
this.networkInterface = networkInterface as NetworkInterface;
CreateEventLog();
}
示例9: getReceivedTraffic
/*
* Get received traffic
* returns String[] array
*/
public long getReceivedTraffic( NetworkInterface conn )
{
IPInterfaceProperties properties = conn.GetIPProperties();
IPv4InterfaceStatistics ipstat = conn.GetIPv4Statistics();
return ipstat.BytesReceived;
}
示例10: NetInterface
public NetInterface(int id, string name, NetInterfaceType type, NetworkInterface netIface)
{
NetshId = id;
Name = name;
Type = type;
networkInterface = netIface;
}
示例11: 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;
}
示例12: NetworkAdapter
public NetworkAdapter(NetworkInterface networkInterface)
{
_networkInterface = networkInterface;
Thread timer = new Thread(UpdateNetworkInterface);
timer.IsBackground = true;
timer.Start();
}
示例13: UploadSpeedEvent
public UploadSpeedEvent(NetworkInterface inter, int sent, int seconds, int comp)
{
_Interface = inter;
_Sent = sent;
_ToBeFor = seconds;
_Comparator = comp;
_LastValue = inter.GetIPv4Statistics().BytesSent;
_Name = "Upload Speed Usage Event";
}
示例14: DownloadSpeedEvent
public DownloadSpeedEvent(NetworkInterface inter, int received, int seconds, int comp)
{
_Interface = inter;
_Received = received;
_ToBeFor = seconds;
_Comparator = comp;
_LastValue = inter.GetIPv4Statistics().BytesReceived;
_Name = "Download Speed Usage Event";
}
示例15: 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);
}