Skip to content

Instantly share code, notes, and snippets.

@ecx86 ecx86/ipd-3.py
Last active Jan 29, 2020

Embed
What would you like to do?
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
@ecx86

This comment has been minimized.

Copy link
Owner Author

ecx86 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
You can’t perform that action at this time.