our hours
9AM - 3PM
Need help?
Report WAN IP address changes to Discord Webhook
07
December

This script creates a file called ipinfo.db that contains your current WAN IP address. When this script is scheduled to run, it will check to see if if your WAN IP has changed. If it has, it will report back to your Discord webhook.

pip install ipinfo
Script (Copy and paste into a new file ex: checkIP.py)
#You will require Python, pip and ipinfo (installed from pip)
import ipinfo
import requests #dependency
import json

#Your Discord Webhook
url = 'https://discord.com/api/webhooks/123456789123456789/yourwebhook'

#Write Variables
access_token = '123456789yourtoken' #Access Token from your account at https://ipinfo.io/account
handler = ipinfo.getHandler(access_token)
details = handler.getDetails()
ip = details.ip

#Check if file exists, if not create a new file
try:
    f = open("ipinfo.db")
except IOError:
    f = open( 'ipinfo.db', 'w' )
    print("Creating new file ipinfo.db file.")
finally:
    f.close()

previous_ip_file = open('ipinfo.db')
previous_ip = previous_ip_file.read()

print("Previous IP:" + previous_ip)
print("Current IP: " + ip)

f = open( 'ipinfo.db', 'w' )
f.write( ip )
f.close()

if(ip != previous_ip):
    print("IP address has changed")
    data = {}

    data["content"] = "The server IP is: " + ip
    data["username"] = "Server"

    result = requests.post(url, data=json.dumps(data), headers={"Content-Type": "application/json"})

    try:
        result.raise_for_status()
    except requests.exceptions.HTTPError as err:
        print(err)
    else:
        print("Success, code {}.".format(result.status_code))
else:
    print("IP address has not changed")
    

Contact Info

Viau Computer Solutions
PO Box 82
Val Caron, On
P3N 1N6

(705) 626-8428
support@viaucs.com

Do you want to repair your computer?