Skip to content

Instantly share code, notes, and snippets.

@rcx
Last active January 29, 2020 02:54
Show Gist options
  • Save rcx/f569dd449ce7919db96523f2c18cd82f to your computer and use it in GitHub Desktop.
Save rcx/f569dd449ce7919db96523f2c18cd82f to your computer and use it in GitHub Desktop.
Socket server that returns your IP address -- try it online at http://tcpb.in:9999
#!/usr/bin/env python3
from socket import *
s = socket(AF_INET, SOCK_STREAM)
s.bind(('', 9999))
s.listen(1)
while True:
try:
c,a = s.accept()
print(a)
c.send((str(a[0]) + '\n').encode('utf-8'))
c.shutdown(SHUT_RDWR)
c.close()
except KeyboardInterrupt:
break
except:
pass
#!/usr/bin/env python
from socket import *
s = socket(AF_INET, SOCK_STREAM)
s.bind(('', 9999))
s.listen(1)
while True:
try:
c,a = s.accept()
print a
c.send(str(a[0]) + '\n')
c.shutdown(SHUT_RDWR)
c.close()
except KeyboardInterrupt:
break
except:
pass
@rcx
Copy link
Author

rcx commented Nov 18, 2018

Q: Why did you write this? Aren't there a million other services like this?
A: Yes, but...:

  • Many are rate-limited, some heavily making them unbearable.
  • ifconfig.co is behind Cloudflare which makes it absolutely worthless if you are checking for correct routes with Torsocks, proxychains, VPN, etc.
  • Others have hard-to-remember or hard-to-type URLs. For this, simply nc tcpb.in 9999 or curl tcpb.in:9999.
  • For such a simple service, I avoid overkilling with tools such as Docker, Travis, Heroku, Make, and Golang. It's a socket server. Just python suffices.

Q: Don't other features offer other functionality like geoip?
A: Lack of features is a feature. Keep it simple. This makes it compatible with many tools as http support is no longer required, only tcp. Moreover, Geoip API query is a leak and therefore bad security. Plus, most people have their home IP address memorized anyways so Geoip is not so important as distinguishing between home IP or not; hostname is more useful than Geo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment