Linux的ping用python,通过linux进行ping,并以python格式获得输出

我正在尝试创建一个小脚本,提供whois和外部ip并ping一个站点来找到它的雕像。我的代码运行良好,除了ping部分。它是平的,但不是我所要求的3。我试着在ubuntu服务器上运行有什么建议吗?在import os

os.system("clear") # clear the screen

inp = input("Enter your choice from the menu: \n1) To find your external IP address\n2) To check domain name whois information\n3) To check if the website or ip address is up\n")

if (inp == "1"):

print("Your external ip address is: ") # me trying to be smart XD

ip = os.system("dig +short myip.opendns.com @resolver1.opendns.com")

#print("Your external ip address is: %d" % ip)

elif (inp == "2"):

domain = input("Enter the domain you want to whois it: \n")

info = os.system("whois %s" % domain)

print(info)

elif (inp == "3"):

target = input("Enter the url or ip address you want to check:\n")

for x in range(3):

response = os.system("ping %s" % target)

if (response == 1): # how can I decide based on response result ?

print("%s is up" % target)

else:

print("%s is down" % target)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值