zoukankan      html  css  js  c++  java
  • python test online

    # -*- coding: utf-8 -*-
    import subprocess
    import re
    import time
    
    def check_online(ip_address):
              p = subprocess.Popen(["ping.exe", ip_address], stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE, shell = True)
              out = p.stdout.read().decode('gbk')
              print(out)
              print(" ")
              
              reg_receive = 'TTL=dd'
              #reg_receive = "已接收 = d"
              match_receive = re.search(reg_receive, out)
              receive_count = -1
              ConnectFail='NetworkUnreachable'
              if match_receive:
                  receive_count = int(match_receive.group()[4:])
                  #print(match_receive.group())
              if receive_count > 0:    #接受到的反馈大于0,表示网络通
                  print("*"*40)
                  print('Network Reachable!')
                  print("*"*40)
                  print(" ")
                  return 1
                  
                  
              else:
                  print("*"*40)
                  print('Connect Fail!')
                  print("*"*40)
                  print(" ")
                  return 0
                  #time.sleep(10)
                  #check_online(ip_address)
                  
             
         
             
    
    
    if __name__ == '__main__':
         ping_result = check_online("192.168.58.123")
         
  • 相关阅读:
    UITextField的简单操作和实际应用
    iOS
    单例传值
    改良UIScrollView滚动视图
    省市便利 UIPicherView
    滚动视图UIScrollView
    label自适应
    将图像设置成圆形
    笔记
    笔记
  • 原文地址:https://www.cnblogs.com/classics/p/11378521.html
Copyright © 2011-2022 走看看