import subprocess
import ipaddress
import pygsheets
from subprocess import Popen, PIPE
from pprint import pprint
from googleapiclient import discovery
#def append_table(start='A1', end=None, values=None, dimension='ROWS',
overwrite=False)
gc = pygsheets.authorize(service_file="testProj.json")
source_spreadsheet =
gc.open_by_key("1Mc1RbfPZIbxmCiqlRJt_AWJVasrGqA7iLmUkuHHL3tw")
wks = source_spreadsheet.sheet1
network = ipaddress.ip_network('10.70.60.0/23')
for i in network.hosts():
i=str(i)
toping = Popen(['ping', '-c', '3', i], stdout=PIPE)
output=toping.communicate()[0]
hostalive = toping.returncode
if hostalive == 0:
print (i, "Pings")
else:
print (i, "Doesn't ping")
我能够从文件中读取,我只是想弄清楚如何写入它。例如,A列将列出子网中的所有IP,B列将打印出IP是否ping通