xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

如何解决树莓派开机后无法获取到 Wi-Fi IP 问题 All In One

如何解决树莓派开机后无法获取到 Wi-Fi IP 问题 All In One

fix 树莓派开机后无法链接 Wi-Fi IP 问题

image

开机后自动发送 IP

接入到 钉钉/飞书/微信 消息机器人

  1. API 接入
  2. shell 脚本,开机自执行

demos

#!\usr\bin\env python3

# coding: utf8

# import time
from time import sleep
import socket
import requests

def getRaspberryPiIP():
  s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  s.connect(("1.1.1.1", 80))
  ip = s.getsockname()[0]
  s.close()
  print("ip =", ip)
  return ip

def post(ip):
  # ⚠️ token 替换成自己的
  url = "https://sc.ftqq.com/token.send"
  data = "text=%s"% ip
  results = requests.get(url, data)
  print("results =", results)

if __name__ == '__main__':
  # 等待联网
  # time.sleep(20)
  sleep(20)
  while True:
    ip = getRaspberryPiIP()
    if ip == False:
      print("获取网络地址失败 ❌")
      post("获取网络地址失败 ❌")
    else:
      post(ip)
    break
# time.sleep(5)
# sleep(5)

"""

https://sc.ftqq.com/


$ sudo vim /etc/rc.local

修改 /etc/rc.local, 在 exit 0 之前添加

/usr/bin/python /home/pi/ip-robot.py & sudo reboot

/usr/bin/python3 /home/pi/ip-robot.py && sudo reboot

"""

(🐞 反爬虫测试!打击盗版⚠️)如果你看到这个信息, 说明这是一篇剽窃的文章,请访问 https://www.cnblogs.com/xgqfrms/ 查看原创文章!

libs

requests

https://pypi.org/project/requests/

https://requests.readthedocs.io/en/latest/

https://github.com/psf/requests

Raspberry Pi Beginner's Guide 4th Edition

November 2020

https://magpi.raspberrypi.com/books/beginners-guide-4th-ed

refs

https://github.com/xgqfrms/dd-robot-notice

How to use SSH to access the Raspberry Pi without know the Wi-Fi IP address All In One

如何在不知道 Wi-Fi IP 地址的情况下使用 SSH 访问树莓派

https://www.cnblogs.com/xgqfrms/p/17322254.html

ifconfig / ipconfig

https://www.cnblogs.com/xgqfrms/p/12084380.html



©xgqfrms 2012-2021

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


posted @ 2023-04-01 15:13  xgqfrms  阅读(137)  评论(9编辑  收藏  举报