Skip to content

Instantly share code, notes, and snippets.

@hypnoJerk
Created April 7, 2016 08:36
Show Gist options
  • Save hypnoJerk/d801013d2089c0fdbbfe8449ede4c626 to your computer and use it in GitHub Desktop.
Save hypnoJerk/d801013d2089c0fdbbfe8449ede4c626 to your computer and use it in GitHub Desktop.
Simple Python script uses cURL to make a txt file with your devices external IP address. After that, you can email it, tweet it, or anything you want. I use this with my Raspberry Pi, and a Twitter bot
import os
def erase_file():
with open('/home/user/external_ip_output.txt', 'w'):
pass
def get_ip():
stream = os.popen('curl ifconfig.me --max-time 7 -o /home/user/external_ip_output.txt')
return stream
def open_file():
f = open('/home/user/external_ip_output.txt', 'r')
text = f.read()
f.close()
return text
def main():
got_ip = False
while got_ip is False:
get_ip()
text = open_file()
if len(text) < 1:
print "Timed Out."
else:
print open_file()
got_ip = True
erase_file()
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment