如何使用Python检查IP是向上还是向下检查

发布于 2025-02-11 00:24:12 字数 48 浏览 1 评论 0原文

我想检查我的IP服务器是否在项目中是否打开,但是使用Python有人可以帮助我吗?

I want to check if my ip server is on or no for a project but using python can someone help me?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

野味少女 2025-02-18 00:24:12

请参阅下面的代码 - 粘贴您要检查状态代码是否为200的URL链接,它是可访问的,其他无法访问意味着站点下降。

import requests
page = requests.get('https://en.wikipedia.org/wiki/Akki')

if page.status_code==200:
    print("Server is up ")
else:
    print("Server is down")

See below code - paste the UrL link which you want to check if status code is 200 it is accessible else not accessible means site is down .

import requests
page = requests.get('https://en.wikipedia.org/wiki/Akki')

if page.status_code==200:
    print("Server is up ")
else:
    print("Server is down")
卖梦商人 2025-02-18 00:24:12

请尝试

import os 
my_hostname='142.251.40.206'
ip_UP  = True if os.system("ping -c 1 " + my_hostname) == 0 else False
print(ip_UP)

Please try this

import os 
my_hostname='142.251.40.206'
ip_UP  = True if os.system("ping -c 1 " + my_hostname) == 0 else False
print(ip_UP)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文