public static void NetworkInterface(NetworkInterface networkInterface) { DebugWrapper.Print(String.Empty); switch (networkInterface.NetworkInterfaceType) { case NetworkInterfaceType.Ethernet: DebugWrapper.Print("Ethernet adapter:"); break; case NetworkInterfaceType.Wireless80211: DebugWrapper.Print("Wireless LAN adapter WI-FI:"); break; default: DebugWrapper.Print("Unknown adapter:"); break; } DebugWrapper.Print(String.Empty); DebugWrapper.Print(" Physical Address. . . . . . . . . : " + Format.GetPhysicalAddress(networkInterface.PhysicalAddress)); DebugWrapper.Print(" DHCP Enabled. . . . . . . . . . . : " + Format.BoolToYesNo(networkInterface.IsDhcpEnabled)); DebugWrapper.Print(" IPv4 Address. . . . . . . . . . . : " + networkInterface.IPAddress); DebugWrapper.Print(" Subnet Mask . . . . . . . . . . . : " + networkInterface.SubnetMask); DebugWrapper.Print(" Default Gateway . . . . . . . . . : " + networkInterface.GatewayAddress); DebugWrapper.Print(String.Empty); DebugWrapper.Print(" DNS Servers . . . . . . . . . . . : " + networkInterface.DnsAddresses[0]); DebugWrapper.Print(" Dynamic DNS Enabled . . . . . . . : " + Format.BoolToYesNo(networkInterface.IsDynamicDnsEnabled)); if (networkInterface.DnsAddresses.Length > 1) DebugWrapper.Print(" " + networkInterface.DnsAddresses[1]); DebugWrapper.Print(String.Empty); }
public static NetworkInterface[] GetAllNetworkInterfaces() { int count = GetNetworkInterfaceCount(); NetworkInterface[] ifaces = new NetworkInterface[count]; for (uint i = 0; i < count; i++) { ifaces[i] = GetNetworkInterface(i); } return ifaces; }
private void BuildMessage(NetworkInterface NetIf, string HostName) { MemoryStream ms = new MemoryStream(_msg); WriteValue(ref ms, 0, Encoding.UTF8.GetBytes(HostName)); WriteValue(ref ms, 66, Encoding.UTF8.GetBytes(NetIf.IPAddress)); WriteMAC(ref ms, NetIf.PhysicalAddress); ms.Dispose(); }
private void Init_UDP(NetworkInterface NetIf, string HostName) { byte[] dst = IPAddress.Parse("239.0.0.222").GetAddressBytes(); byte[] src = IPAddress.Any.GetAddressBytes(); byte[] val = new byte[] { dst[0], dst[1], dst[2], dst[3], src[0], src[1], src[2], src[3] }; _mSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); _mSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); _mSocket.Bind(new IPEndPoint(IPAddress.Any, 6)); _mSocket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, val); _remote = new IPEndPoint(IPAddress.Parse("239.0.0.222"), 6); BuildMessage(NetIf, HostName); }
public void Restore(NetworkInterface networkInterface) { Log.Comment("Return the IP settings to their original state before the test started"); if (m_dhcp) { Log.Comment("EnableDhcp"); networkInterface.EnableDhcp(); } else { Log.Comment("EnableStaticIP"); networkInterface.EnableStaticIP(m_ipAddress, m_subNetMask, m_gatewayAddress); } if (m_dynamicDns) { Log.Comment("EnableDynamicDns"); networkInterface.EnableDynamicDns(); } else { Log.Comment("EnableStaticDns"); networkInterface.EnableStaticDns(m_staticDnsAddresses); } }
//--// public IPSettings(NetworkInterface networkInterface) { Log.Comment("store off the settings so that they can be reset to users settings upon completion of the test."); m_dhcp = networkInterface.IsDhcpEnabled; m_dynamicDns = networkInterface.IsDynamicDnsEnabled; m_ipAddress = networkInterface.IPAddress; m_subNetMask = networkInterface.SubnetMask; m_gatewayAddress = networkInterface.GatewayAddress; m_macAddress = networkInterface.PhysicalAddress[0].ToString(); for (int j = 1; j < networkInterface.PhysicalAddress.Length; ++j) { m_macAddress += "-" + networkInterface.PhysicalAddress[j].ToString(); } m_staticDnsAddresses = new string[] { "0.0.0.0", "0.0.0.0" }; for (int i = 0; i < networkInterface.DnsAddresses.Length; ++i) { m_staticDnsAddresses[i] = networkInterface.DnsAddresses[i]; } PrintIPSettings(); }
public void RetrieveNetworkSettings(NetworkInterface objNic) { //var objNic = Microsoft.SPOT.Net.NetworkInformation.Wireless80211.GetAllNetworkInterfaces()[0]; //var objNic = Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()[0]; IsDhcpEnabled = objNic.IsDhcpEnabled; NetworkInterfaceType = objNic.NetworkInterfaceType; IPAddress = objNic.IPAddress; NetMask = objNic.SubnetMask; MACAddress = objNic.PhysicalAddress.ToHexString(); Gateway = objNic.GatewayAddress; DnsAddresses = objNic.DnsAddresses; Debug.Print("Is DHCP Enabled: " + objNic.IsDhcpEnabled); Debug.Print("NIC Type: " + objNic.NetworkInterfaceType.GetName()); Debug.Print("MAC Address: " + MACAddress); Debug.Print("IP Address: " + IPAddress); Debug.Print("NetMask: " + NetMask); Debug.Print("Gateway: " + objNic.GatewayAddress); foreach (var strDnsAddress in DnsAddresses) Debug.Print("Dns address: " + strDnsAddress); }
private void FixIPAddress(NetworkInterface ni) { if (ni.IsDhcpEnabled) { ni.RenewDhcpLease(); Thread.Sleep(500); ipAddress = ni.IPAddress; if (ipAddress == "0.0.0.0") { ipAddress = ni.IPAddress; } } else { ni.EnableDhcp(); Thread.Sleep(500); ipAddress = ni.IPAddress; } }
public string SetupNetwork() { Thread.Sleep(500); var nifs = NetworkInterface.GetAllNetworkInterfaces(); var enetifs = new NetworkInterface[nifs.Length]; int enetifIndex = 0; foreach (var ni in nifs) { if (ni.NetworkInterfaceType == NetworkInterfaceType.Ethernet) { ipAddress = ni.IPAddress; if (ipAddress != null && ipAddress != "0.0.0.0") { break; } enetifs[enetifIndex++] = ni; FixIPAddress(ni); } } if (ipAddress != "0.0.0.0") { isNetworkConnected = true; } else { int tryCount = 1; while (tryCount < ConnectTryCount && ipAddress == "0.0.0.0") { foreach (var ni in enetifs) { if (ni != null) { Thread.Sleep(500); ipAddress = ni.IPAddress; } } tryCount++; } } return ipAddress; }