c# - Problem Converting ipv6 to ipv4 -


i have code in asp.net app needsto ipv4 address of client computer (the users on our own network). upgraded server app runs on windows 2008 server. request.userhostaddress code returns ipv4 when client on older os , ipv6 when on newer os (vista , higher). feature relys on works clients , not others.

i added code supposed convert ipv6 ipv4 try fix problem. it's online tutorial: http://www.4guysfromrolla.com/articles/071807-1.aspx .i'm using dsn.gethostaddress , looping through ips returned looking 1 "internetwork"

foreach (ipaddress ipa in dns.gethostaddresses(httpcontext.current.request.userhostaddress)) {     if (ipa.addressfamily.tostring() == "internetwork")     {         ip4address = ipa.tostring();         break;     } }  if (ip4address != string.empty) {     return ip4address; }   foreach (ipaddress ipa in dns.gethostaddresses(dns.gethostname())) {     if (ipa.addressfamily.tostring() == "internetwork")     {         ip4address = ipa.tostring();         break;     } }  return ip4address; 

the problem isn't working me. clients connecting ipv4 continue return correct ipv4 ip of client computer, clients connecting vista , windows 7 returning ipv4 ip of server machine not client computer.

simple answer: disable ipv6 on server, or remove ipv6 address of server dns entry.

there not magic ipv4<->ipv6 converter. they're different protocols, , addresses in 1 don't translate other. if want reliably retrieve ipv4 address of client, need make sure client connects on ipv4.


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -