Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using icanhazip.com to find IP with mechanize in python, output not what I expected

I am using icanhazip.com to find my ip address. When I go to that site with a browser, my ip is output in a way I usually see it: 174.xx.xx.xx

When I use python and mechanize to get my ip from icanhazip.com, I get this result: 2001:4800:7810:512:13b2:ccd5:ff04:c5f4

I'm sure it's just a representation of the ip address in a way I have never seen. How do I convert that to the form that I am used to?

Thanks in advance.

In [9]: br.open("http://icanhazip.com/")
Out[9]: <response_seek_wrapper at 0x30bbe60 whose wrapped object = <closeable_response at 0x30bb0e0 whose fp = <socket._fileobject object at 0x2dd5ed0>>>

In [10]: br.open("http://icanhazip.com/").read()
Out[10]: '2001:4800:7810:512:13b2:ccd5:ff04:c5f4\n'

In [11]: print br.open("http://icanhazip.com/").read()
2001:4800:7810:512:13b2:ccd5:ff04:c5f4
like image 414
dmmfll Avatar asked Oct 15 '25 03:10

dmmfll


1 Answers

I'm the operator of icanhazip.com and I get this question a lot. I have two additional DNS records that will help you get the result you want. If you want to force an IPv4 lookup, use ipv4.icanhazip.com. For IPv6, use ipv6.icanhazip.com.

If you access just icanhazip.com, the result you see is dependent upon how your computer is configured to use IPv4 or IPv6 networking. Most operating systems default to IPv6 (if it's available for use).

like image 106
majorhayden Avatar answered Oct 17 '25 19:10

majorhayden



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!