開機時,樹莓派主動發送本身的內網ip以及公網ip到你的微信上,這樣就能方便地使用ssh或VNC。python
很是簡潔了git
# -*- coding: utf-8 -*- # author : ziheng_wind """ 感謝前人留下的資料 學無止盡 """ import requests import socket import time def getip(): time.sleep(15) ip = requests.get('http://ip.42.pl/raw').text try: s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.connect(('8.8.8.8', 80)) ip_1 = s.getsockname()[0] finally: s.close() desp = "- 公網IP"+ip + "- 局域網IP"+ip_1 print(desp) data = { 'text': '俺上線啦 這是俺的IP 還有局域網IP', 'desp': desp } req = requests.post('https://sc.ftqq.com/YOUR_KRY.send', data=data) getip() if __name__ == "__main__": pass
參考連接:https://github.com/nonewind/Raspberry_Boot_sendIPgithub