2

How can i find my ip address with python not local ip ? I try with socket but it find local ip.I need to ethernet outer ip.That's my code but it find local ip

import socket
hostname = socket.gethostname()
IPAddr = socket.gethostbyname(hostname)
print("Your Computer Name is:" + hostname)
print("Your Computer IP Address is:" + IPAddr)
Oguzhan
  • 21
  • 1
  • 5

1 Answers1

5

I used to have this problem and this was my solution:

you should install this package then:

import requests

...

public_ip = requests.get("http://wtfismyip.com/text").text

print(public_ip)

It's not possible to get the public IP using socket

maghsood026
  • 190
  • 7