Bonjour fredericmazue,
J'ai essayé d'envoyer mes données ds un fichier : c:/tmp/workfile.txt
tout semble super, mais seulement une seule ligne apparaît ds mon dossier ? J'ai presque tout essayé, genre créer un objet appellé file_open()
mais en vain. Voici ce que j'écris (voir en gras):
import os
import re
def validIP(ipAddress):
ipRegex = r"^([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])$"
re_ip = re.compile(ipRegex)
return re_ip.match(ipAddress)
def read_ip(N):
valid_ip1 = []
i = 1
while (i<=N or N==0):
ipAddress = raw_input("#IP no. %d: " %i)
if N==0 and ipAddress=="0":
return valid_ip1
if validIP(ipAddress):
valid_ip1.append(ipAddress)
i += 1
else:
print "IP invalid. start again"
ips = read_ip(0)
print ips
results = []
def print_results():
for result in results:
for line in result:
print line
def analyse():
for result in results:
for line in result:
mo = re.search("loss" , line)
if(mo):
startopenbracket = line.find("(")
startloss = line.find("loss")
print line [startopenbracket+1:startloss]
print line
f=open('c:/tmp/workfile.txt', 'w')
f.write(line)
f.close()
def build_commande(ip):
return "ping -n 4" + " " + ip
def do_command(command):
results.append("-----------")
tube = os.popen(command, "r")
results.append(tube.readlines())
tube.close()
for ip in ips:
command = build_commande(ip)
do_command(command)
print_results()
analyse()
Bonjour fredericmazue,
J'ai essayé d'envoyer mes données ds un fichier : c:/tmp/workfile.txt
tout semble super, mais seulement une seule ligne apparaît ds mon dossier ? J'ai presque tout essayé, genre créer un objet appellé file_open()
mais en vain. Voici ce que j'écris (voir en gras):
import os import re def validIP(ipAddress): ipRegex = r"^([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])$" re_ip = re.compile(ipRegex) return re_ip.match(ipAddress) def read_ip(N): valid_ip1 = [] i = 1 while (i<=N or N==0): ipAddress = raw_input("#IP no. %d: " %i) if N==0 and ipAddress=="0": return valid_ip1 if validIP(ipAddress): valid_ip1.append(ipAddress) i += 1 else: print "IP invalid. start again" ips = read_ip(0) print ips results = [] def print_results(): for result in results: for line in result: print line def analyse(): for result in results: for line in result: mo = re.search("loss" , line) if(mo): startopenbracket = line.find("(") startloss = line.find("loss") print line [startopenbracket+1:startloss] print line f=open('c:/tmp/workfile.txt', 'w') f.write(line) f.close() def build_commande(ip): return "ping -n 4" + " " + ip def do_command(command): results.append("-----------") tube = os.popen(command, "r") results.append(tube.readlines()) tube.close() for ip in ips: command = build_commande(ip) do_command(command) print_results() analyse()