【发布时间】:2021-10-20 07:52:39
【问题描述】:
你能分享一个 Python 程序吗?我只需要从一系列文本中解析 IP 并 ping IP
文本文件:
IP 地址:x.x.x.x 子网:x.x.x.x
【问题讨论】:
你能分享一个 Python 程序吗?我只需要从一系列文本中解析 IP 并 ping IP
文本文件:
IP 地址:x.x.x.x 子网:x.x.x.x
【问题讨论】:
这是一个 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])
【讨论】: