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

Adding support for IPv6 in IPv4 client/server apps – sin6_flowinfo and sin6_scope_id fields?

The best way to go is to use getaddrinfo(). Pseudo code: struct addrinfo *restrict hints = { .ai_family = AF_UNSPEC, .ai_socktype = SOCK_STREAM }; struct addrinfo * res, r; if (0 == getaddrinfo(“foo.bar.baz”, “http”, &hints, &res)) { for (r=res; r; r=r->ai_next) { sock = socket(r->ai_family, r->ai_socktype, r->ai_protocol); connect(sock, r->ai_addr, r->ai_addrlen); if error: continue break } … Read more

Why is INET6_ADDRSTRLEN defined as 46 in C?

Why is INET6_ADDRSTRLEN defined as 46 in C? Because POSIX defines it to be 46: INET6_ADDRSTRLEN 46. Length of the string form for IPv6. While you are right that longtest IPv6 address takes 39 bytes, with IPv4 tunneling, the longest form can be 45 bytes: ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255 And the 46th byte is for the terminating nul … 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

tech