Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0f854d8

Browse files
raspberry piのip通知
1 parent bb541c3 commit 0f854d8

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

sendIP.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env python3
2+
# Copyright (c) 2022. 楊鵬. All Rights Reserved.
3+
import socket
4+
5+
import requests
6+
7+
URL = "https://notify-api.line.me/api/notify"
8+
TOKEN = "mCfw9Yzf8MsXuW2caAPYOkNl7nSewwYppdmV97VRWn6"
9+
10+
11+
def sendIP(ip: str):
12+
headers = {"Authorization": "Bearer " + TOKEN}
13+
params = {"message": ip}
14+
r = requests.post(URL, headers=headers, params=params)
15+
print(r.text)
16+
17+
18+
if __name__ == "__main__":
19+
connect_interface = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
20+
connect_interface.connect(("8.8.8.8", 80))
21+
ip_addr = connect_interface.getsockname()[0]
22+
connect_interface.close()
23+
message = f"IP Address: {ip_addr}"
24+
sendIP(message)

0 commit comments

Comments
 (0)