FreshPepsi
FreshPepsi

Reputation: 15

Cant print a value

I try to get my public ipv4 with the url bellow but when I ask to print it prints none can you guys tell me why ?

code :

def GetIp():

    url = "http://www.whatismyip.com?"

    result = requests.get(url)

    result = str(result)

    regex = "^([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(?<!172\.(16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31))(?<!127)(?<!^10)(?<!^0)\.([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(?<!192\.168)(?<!172\.(16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31))\.([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(?<!\.255$)$"

    match = re.search(regex,result)

    print(str(match))

Upvotes: 0

Views: 47

Answers (1)

weegolo
weegolo

Reputation: 396

>>> import requests
>>> print requests.get("http://www.whatismyip.com/")
<Response [403]>

Looks like the site is refusing your request. Maybe they don't like scripted requests that don't trigger their adverts. Here's an alternate approach:

>>> print (requests.get("http://ident.me").text)
118.189.157.2

Upvotes: 2

Related Questions