【问题标题】:Parse IP from text then ping IP从文本中解析 IP 然后 ping IP
【发布时间】:2021-10-20 07:52:39
【问题描述】:

你能分享一个 Python 程序吗?我只需要从一系列文本中解析 IP 并 ping IP

文本文件:

IP 地址:x.x.x.x 子网:x.x.x.x

【问题讨论】:

    标签: parsing ip ping


    【解决方案1】:

    这是一个 Python 解决方案:

        #This is a program to read a file and ping the IP address found in the first line of
    import subprocess
    #IP Address: x.x.x.x with subnet: x.x.x.x
    file = open("file.txt", "r")
    fileContent = file.read()
    # now parsing the file
    fileSplitted = fileContent.split()
    ipAddress = fileSplitted[2]
    print(ipAddress)
    subprocess.Popen(["ping", ipAddress])
    

    【讨论】:

      猜你喜欢
      • 2023-01-25
      • 1970-01-01
      • 2013-06-14
      • 2016-03-03
      • 2016-12-10
      • 2015-01-19
      • 1970-01-01
      • 2018-10-05
      • 1970-01-01
      相关资源
      最近更新 更多