-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_google_ip_changes.py
51 lines (41 loc) · 1.47 KB
/
check_google_ip_changes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import json
import smtplib
import os
import requests
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from deepdiff import DeepDiff
SMTP_USERNAME = os.environ["SMTP_USERNAME"]
SMTP_PASSWORD = os.environ["SMTP_PASSWORD"]
SENDER_EMAIL = os.environ["SENDER_EMAIL"]
RECIPIENT_EMAIL = os.environ["RECIPIENT_EMAIL"]
#Replace with your SMTP Server Credentials
SMTP_SERVER = "SMTPServer"
SMTP_PORT = 25
USE_TLS = False
def send_email(subject, body):
msg = MIMEMultipart()
msg["From"] = SENDER_EMAIL
msg["To"] = RECIPIENT_EMAIL
msg["Subject"] = subject
msg.attach(MIMEText(body, "plain"))
with smtplib.SMTP(SMTP_SERVER, SMTP_PORT) as smtp:
if USE_TLS:
smtp.starttls()
smtp.login(SMTP_USERNAME, SMTP_PASSWORD)
smtp.sendmail(SMTP_USERNAME, RECIPIENT_EMAIL, msg.as_string())
def main():
with open("previous_data.json", "r") as file:
previous_data = json.load(file)
response = requests.get(
"https://www.gstatic.com/ipranges/goog.json"
)
current_data = response.json()
diff = DeepDiff(previous_data, current_data, exclude_paths=["root['syncToken']", "root['creationTime']"])
if diff:
differences = json.dumps({"old": previous_data, "new": current_data}, indent=2)
send_email("Google IP Changes Detected", differences)
with open("previous_data.json", "w") as file:
json.dump(current_data, file, indent=2)
if __name__ == "__main__":
main()