Raspberry Pi turned on their own initiative to send LAN ip / ip outside the network to your micro letter

Boot, Raspberry Pi sends its own network and public network ip ip to your micro-channel, so you can easily use ssh or VNC.

Steps

  • boot_getIP_send_Wechat.py under the download directory to your Raspberry
  • Into the sugar cubes [ http://sc.ftqq.com/3.version ] landing to get your key bindings and micro-letters, and then replace the code in your YOUR_KRY
  • Remote connection Raspberry
  • Import sudo nano /etc/rc.local
  • Add a line of code eg execution before exit 0: python / absolute path /boot_getIP_send_Wechat.py >> / absolute path /log.log 2> & 1 Save and Exit
  • Restart Raspberry Pi wait 15s to see the phone micro letter!

Code

A very simple

# - * - Coding: UTF-8 - * - 
# author: ziheng_wind 

"" " 
thank data left by their predecessors 
learned endless 
" "" 
Import Requests
 Import socket
 Import Time 


DEF Getip (): 

    the time.sleep ( 15 ) 
    IP = requests.get ( ' http://ip.42.pl/raw ' ) .text
     the try : 
        S = socket.socket (socket.AF_INET, socket.SOCK_DGRAM) 
        s.connect (( ' 8.8.8.8 ' , 80 )) 
        IP_1 = s.getsockname () [0]
     the finally: 
        S.CLOSE () 
    DESP = " - public IP " + IP + " - LAN IP " + IP_1
     Print (DESP) 
    Data = {
         ' text ' : ' I it on the line I which is an IP LANs, IP ' ,
         ' DESP ' : DESP 
    } 
    REQ = requests.post ( ' https://sc.ftqq.com/YOUR_KRY.send ' , Data = Data) 


Getip () 

IF  the __name__ == " __main__ ":
    pass

 

 

Reference Links: https://github.com/nonewind/Raspberry_Boot_sendIP

Guess you like

Origin www.cnblogs.com/lfri/p/12001686.html