从文本中解析IP然后ping IP



你能给我分享一个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])

相关内容

最新更新