Hack Forums
[Python] Socket Question - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Python] Socket Question (/showthread.php?tid=5715899)



Socket Question - M0therB0ard - Sep 11, 2017

pastebin . com / raw / Sucjf5bW

So with the code I just shown, it's suppose to make a server so people can chat, I am going to make the client later but for now I need to figure out something to make connecting easier.

In th last print statment it's suppose to show the IP the socket is using.

But it shows 0.0.0.0 as the local IP, I thought if I left it empty it would automatically insert my local IP for me.

But now my question is how do I make it show me the IP.

And can you help me so it shows public and not local?


* - vorticalbox - Sep 12, 2017

You can use an external api to get your IP address.
PHP Code

<?php 
Import requests
Import json
with requests
.Session() as s:
        
r = s.get("http://ip-api.com/json", timeout=5)
        
j = json.loads(r.text)
        print(
'my  IP is {0}'.format(j['query']))