Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get IPv6 Address in c#?

I use Request.UserHostAddress, can only get IPv4 address, how to get IPv6 address of a visitor?

like image 499
Eric Yin Avatar asked Feb 01 '12 21:02

Eric Yin


People also ask

How do you check IP address is IPv4 or IPv6 in C?

Given a string S consisting of N characters, the task is to check if the given string S is IPv4 or IPv6 or Invalid. If the given string S is a valid IPv4, then print “IPv4”, if the string S is a valid IPv6, then print “IPv4”. Otherwise, print “-1”. A valid IPv4 address is an IP in the form “x1.

How do I find my IPv6 config?

Test an IPv6 configuration by using the PING command To obtain the IPv6 configuration for a computer: Click Start, point to All Programs, point to Accessories, and then click Command Prompt. At the command prompt, type ping ::1 to locate the loopback address.

What is my IPv6 address command line?

Generic unix instructions for determining your IPv6 address and default route: Run ifconfig -a and look for inet6 to see your possible IPv6 addresses. Run netstat -nr and look for inet6 or Internet6 or similar to find the IPv6 portion; then look for default or :: or ::/0 .


2 Answers

An IPv4 address is translated to an IPv6 address by placing the 4 octets of the IPv4 address into the rightmost 4 octets of the IPv6 address.

After inserting the 4 octets of the IPv4 address into the rightmost 4 octets of the IPv6 address, the remaining left-most octets would be 0 in value.

like image 122
Dmitry Savy Avatar answered Sep 22 '22 23:09

Dmitry Savy


I assume you're talking about HttpRequest.UserHostAddress. It will always return the address that was used to connect to you. If the request was made over IPv6, it will return their IPv6 address; if the request was made over IPv4, it will return their IPv4 address.

You should start by investigating why the request is being made over IPv4. And the folks at http://serverfault.com will probably be of more help on that.

like image 24
sblom Avatar answered Sep 20 '22 23:09

sblom