Help making a simple Linux program
Go to solution
Solved by fizzlesticks,
Instead of using curl shouldn't you probe your nic directly? No need to rely on a second service unless you're testing that as well?
Get IP with: ifconfig eth0 | grep "inet addr" | awk '{print $2}' | grep -oP '(?<=addr:).*'
Assuming you are on eth0 and not some other interface.
Don't know if it's because I'm running Linux in a VM but that doesn't return my public IP.
@Jaybird If you have a gmail account you can use this Python3 script I just happen to have laying around.
import json, urllib.request, time, smtplibusername = "XXX@gmail.com"password = "xxxx"def getIP(): try: ip = json.loads(urllib.request.urlopen('http://httpbin.org/ip').read().decode())['origin'] return ip except: return Nonedef sendEmail(ip): try: msg = 'From: {}\r\nTo: {}\r\n\r\nNew IP: {}\r\n'.format(username,username,ip) server = smtplib.SMTP('smtp.gmail.com:587') server.starttls() server.login(username,password) server.sendmail(username, username, msg) server.quit() return True except: return Falsedef main(): ip = getIP() while True: newIP = getIP() if not newIP: time.sleep(30) continue if ip != newIP: while not sendEmail(newIP): pass print("Got new IP: {}".format(newIP)) ip = newIP time.sleep(600)if __name__ == '__main__': main()
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now