ipv4
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
How can I verify that a string is a valid IPv4 or IPv6 address in batch?
Check for valid IPv4: @if (@X)==(@Y) @end /* JScript comment @echo off cscript //E:JScript //nologo “%~f0” %* exit /b %errorlevel% @if (@X)==(@Y) @end JScript comment */ WScript.Quit(ValidateIPaddress(WScript.Arguments.Item(0))); function ValidateIPaddress(ipaddress) { return !(/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(ipaddress)) } For valid IPv6 address: @if (@X)==(@Y) @end /* JScript comment @echo off cscript //E:JScript //nologo “%~f0” %* exit /b %errorlevel% @if (@X)==(@Y) … 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
How to set java.net.preferIPv4Stack=true at runtime?
You can use System.setProperty(“java.net.preferIPv4Stack” , “true”); This is equivalent to passing it in the command line via -Djava.net.preferIPv4Stack=true
Configure git to use IPv4 instead of IPv6 by default
The more generic solution (that also works for BSD) is to edit the global /etc/ssh/ssh_config or per-user ~/.ssh/config and add/replace the entry: AddressFamily any with the following line (where inet corresponds to ipv4): AddressFamily inet You can also set this for just a single host: Host example.com AddressFamily inet
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
Get IPv4 addresses from Dns.GetHostEntry()
Have you looked at all the addresses in the return, discard the ones of family InterNetworkV6 and retain only the IPv4 ones?
What is the total amount of public IPv4 addresses?
According to Reserved IP addresses there are 588,514,304 reserved addresses and since there are 4,294,967,296 (2^32) IPv4 addressess in total, there are 3,706,452,992 public addresses. And too many addresses in this post.
How to support both IPv4 and IPv6 connections
The best approach is to create an IPv6 server socket that can also accept IPv4 connections. To do so, create a regular IPv6 socket, turn off the socket option IPV6_V6ONLY, bind it to the “any” address, and start receiving. IPv4 addresses will be presented as IPv6 addresses, in the IPv4-mapped format. The major difference across … Read more