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

"""

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-2025

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

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


posted @   xgqfrms  阅读(146)  评论(9编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
历史上的今天:
2022-04-01 HTML Input Element in depth All In One
2022-04-01 CSS tint() function All In One
2022-04-01 TypeScript override & overload All In One
2022-04-01 TypeScript & Node.js crawler All In One
2022-04-01 StackOverflow Filters All In One
2022-04-01 TypeScript FAQ All In One
2022-04-01 TypeScript Compiler All in One
点击右上角即可分享
微信分享提示