IIS Request.UserHostAddress returning IPV6 (::1), even when IPV6 disabled

The 4 Guys from Rolla website has a solution here, which I’ve used in my app. Update: Just in case this link goes dead, here is code based on this link: public string GetIpAddress() { string ipAddressString = HttpContext.Current.Request.UserHostAddress; if (ipAddressString == null) return null; IPAddress ipAddress; IPAddress.TryParse(ipAddressString, out ipAddress); // If we got an … Read more

What is the most appropriate data type for storing an IP address in SQL server? [duplicate]

Storing an IPv4 address as a binary(4) is truest to what it represents, and allows for easy subnet mask-style querying. However, it requires conversion in and out if you are actually after a text representation. In that case, you may prefer a string format. A little-used SQL Server function that might help if you are … Read more

Get local network interface addresses using only proc?

/proc/net/fib_trie holds the network topography To simply print the addresses of all adapters: $ awk ‘/32 host/ { print f } {f=$2}’ <<< “$(</proc/net/fib_trie)” 127.0.0.1 192.168.0.5 192.168.1.14 To determine the adapter of those addresses (a) consult the adapters’ destination networks from /proc/net/route, (b) match those networks with the ones of /proc/net/fib_trie and (c) print the … Read more

Script to change ip address on windows

You can use the Python WMI module to do this (install the PyWin32 extensions and the WMI module before running these scripts). Here is how to configure things to talk to the hardware device: import wmi # Obtain network adaptors configurations nic_configs = wmi.WMI().Win32_NetworkAdapterConfiguration(IPEnabled=True) # First network adaptor nic = nic_configs[0] # IP address, subnetmask … Read more

What is IPV6 for localhost and 0.0.0.0?

As we all know that IPv4 address for localhost is 127.0.0.1 (loopback address). Actually, any IPv4 address in 127.0.0.0/8 is a loopback address. In IPv6, the direct analog of the loopback range is ::1/128. So ::1 (long form 0:0:0:0:0:0:0:1) is the one and only IPv6 loopback address. While the hostname localhost will normally resolve to … Read more

Force requests to use IPv4 / IPv6

I’ve found a minimalistic solution to force urrlib3 to use either ipv4 or ipv6. This method is used by urrlib3 for creating new connection both for Http and Https. You can specify in it any AF_FAMILY you want to use. import socket import requests.packages.urllib3.util.connection as urllib3_cn def allowed_gai_family(): “”” https://github.com/shazow/urllib3/blob/master/urllib3/util/connection.py “”” family = socket.AF_INET if … Read more

Get destination address of a received UDP packet

I’ve constructed an example that extracts the source, destination and interface addresses. For brevity, no error checking is provided. // sock is bound AF_INET socket, usually SOCK_DGRAM // include struct in_pktinfo in the message “ancilliary” control data setsockopt(sock, IPPROTO_IP, IP_PKTINFO, &opt, sizeof(opt)); // the control data is dumped here char cmbuf[0x100]; // the remote/source sockaddr … Read more

How to configure a static IP address, netmask, gateway programmatically on Android 3.x or 4.x

I realise that there is no API on 3.x or 4.x for those setting per SSID. Therefore, I checked out the source code and found out that the configuration of each SSID is stored in android.net.wifi.WifiConfiguration which is gotten from android.net.wifi.WifiManager. In the below code, IpAssignment is an Enum, either STAIC, DHCP or NONE. And … Read more