Hi,
I have to below script,
and everything seems to work except
that if I entered the Primary IP and Secondaries IP, with such
number; 10.100.1.11 or 10.10.10.245 the last numbers of my IP are missing
in my logs file (c:/tmp/myprimarylogs.xls) Here is the result, you see, '10.100.1.1 should be 10.100.1.11
and 10.10.10.2 should be 10.10.10.224 how can I resolve this issue ?
and I need to know How to add the time : time.asctime() beside my IP on below logs ?
is this possible to put every result with a proper column in Excel file (myprimarylogs.xls) as these result are not properly separate all the purcentage will be on column A, all the IP in column B and time in column C. -
-
10 %'10.10.1.1'
-
10 %'10.10.1.1'
-
20% '10.10.10.2'
-
-
Here is my code. -
-
import re
-
import time
-
import thread
-
import os
-
import sys
-
-
f=open('c:/tmp/primaryip.xls','w')
-
f.close()
-
-
g=open('c:/tmp/workfile.txt','w')
-
g.close()
-
-
h=open('c:/tmp/myprimarylogs.txt','w')
-
h.close()
-
-
j=open('c:/tmp/secip.xls','w')
-
j.close()
-
-
def validIP(ipAdd):
-
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(ipAdd)
-
-
def validIP1(ipAdd1):
-
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(ipAdd1)
-
-
def fil(data):
-
patt = re.compile(r'\((\d+)% loss\)')
-
patt1 = re.compile(r'(\d+.\d+.\d+.\d)')
-
line = str(loss_num) + tab + str(ip) + tab + str(out_time) + '\n'
-
for line in data.split('\n'):
-
-
if line.startswith("Ping statistics for"):
-
ip = patt1.search(line).group(1)
-
-
if patt.search(line):
-
loss_num = int(patt.search(line).group(1))
-
-
if loss_num >= 2 :
-
s = open('c:/tmp/myprimarylogs.txt', 'a+')
-
s.write("%s '%s'\n" % (loss_num, ip))
-
#s.write("%s '%s'\n" % (loss_num, ip) + time.asctime())
-
s.close()
-
# if loss >= 2, return False - then secondary IPs are pinged
-
print 'loss_num is >= 2 ', loss_num , ip , time.asctime()
-
return False
-
else:
-
print 'loss_num is < 2,', loss_num , ip , time.asctime()
-
return True
-
-
def ping(*fnames):
-
g = open(fnames[0], 'w')
-
for fn in fnames[1:]:
-
f=open(fn, 'r')
-
ipList = [line.strip() for line in f.readlines()]
-
f.close()
-
resList = []
-
for ipAdd in ipList:
-
pingaling =os.popen("ping %s -n 10" %(ipAdd),"r")
-
data = pingaling.read()
-
resList.append(data)
-
# if loss > 2, ping secondary IPs
-
proceed = fil(data)
-
if proceed:
-
break
-
g.write('/n'.join(resList))
-
if proceed:
-
break
-
g.close()
-
-
def get_IPs(fnP, fnS):
-
while True:
-
ipAddP = raw_input("# Enter Primary IP: ")
-
if validIP(ipAddP):
-
f = open(fnP, 'w')
-
f.write(ipAddP.strip() + "\n")
-
f.close()
-
break
-
else:
-
print "Invalid IP."
-
ipList = []
-
while True:
-
while True:
-
ipAddS = raw_input("# Enter Secondary IP: ")
-
if validIP(ipAddS):
-
ipList.append(ipAddS.strip())
-
break
-
else:
-
print "Invalid IP"
-
s = raw_input("# Enter another IP? Y/N: " )
-
if s.upper() == "N":
-
f = open(fnS, 'w')
-
f.write('\n'.join(ipList))
-
f.close()
-
break
-
-
fnP = 'c:/tmp/primaryip.xls'
-
fnS = 'c:/tmp/secip.xls'
-
fnW = 'c:/tmp/workfile.txt'
-
-
#get_IPs(fnP, fnS)
-
#ping(fnW, fnP, fnS)
-
-
def main():
-
the_time = time.time()
-
start_time = the_time
-
end_time = the_time + (60*60) # 1 hr
-
#end_time = the_time + (60*60*24) # 24 hrs
-
get_IPs(fnP, fnS)
-
while the_time < end_time:
-
ping(fnW, fnP, fnS)
-
time.sleep(10) # wait 60 seconds
-
the_time = time.time() # get the new time
-
-
-
if __name__ == "__main__":
-
main()
-
10 2406
It's the regex that you are using in the logging routine: -
>>> patt1 = re.compile(r'(\d+.\d+.\d+.\d)')
-
>>> m = patt1.match('2.192.100.100')
-
>>> m.group(1)
-
'2.192.100.1'
-
>>>
Hi Bartonc,
thanks did changed the syntaxe now it is ok.
a)I would like to add the time to my logs( SEE line 15 and 16), I did tried
several combinaisons but does not seems to work
b)And how can I add the different type of data within a different column, in this case all my data goes into column A but I want it : A = purcentage, B=IPss, C = time within Excel spreadsheet ? -
-
def fil(data):
-
patt = re.compile(r'\((\d+)% loss\)')
-
patt1 = re.compile(r'(\d+.\d+.\d+.\d+)')
-
#line = str(loss_num) + tab + str(ip) + tab + str(out_time) + '\n'
-
for line in data.split('\n'):
-
-
if line.startswith("Ping statistics for"):
-
ip = patt1.search(line).group(1)
-
-
if patt.search(line):
-
loss_num = int(patt.search(line).group(1))
-
-
if loss_num >= 2 :
-
s = open('c:/tmp/myprimarylogs.txt', 'a+')
-
t = time.asctime()
-
s.write("%s '%s'\n" % (loss_num, ip)), t
-
#s.write("%s '%s'\n" % (loss_num, ip) + time.asctime())
-
s.close()
-
# if loss >= 2, return False - then secondary IPs are pinged
-
print 'Packets loss are >= 2 ', loss_num , ip , time.asctime()
-
return False
-
else:
-
print 'Packets loss are < 2,', loss_num , ip , time.asctime()
-
return True
-
-
Hi,
Is someone can help me ?
Brgds/Charlie
Hi Bartonc,
forget my last question regarding the time,
I found it too.
But need to know, how can I separte my data to different column in Excel
ei: column A = purcentage, B= IP address, C= Time ?
I think the answer to both the time question and the columns in Excel can be found here, in a tab separated values string: - s.write("%s\t'%s'\t%s\n" % (loss_num, ip, t)) # move the ,t inside the string format parens
Hi, I will try your suggestion later.
Bartonc,
According the my script provide to you on this page,
Do you have any idea on why the script does not provide
The ping from my 5th IP below.
the script only ping 4 IPs instead of 5, the
last ip entered: 2.3.6.8 is not pinged at all. -
# Enter Primary IP: 11.11.11.11
-
# Enter Secondary IP: 10.20.0.246
-
# Enter another IP? Y/N: y
-
# Enter Secondary IP: 1.2.3.4
-
# Enter another IP? Y/N: y
-
# Enter Secondary IP: 10.20.3.173
-
# Enter another IP? Y/N: y
-
# Enter Secondary IP: 2.3.6.8
-
# Enter another IP? Y/N: n
-
Packets loss are > 2: 100 11.11.11.11 Tue Nov 06 13:02:12 2007
-
Packets loss are > 2: 12 10.20.0.246 Tue Nov 06 13:03:13 2007
-
Packets loss are > 2: 100 1.2.3.4 Tue Nov 06 13:06:52 2007
-
Packets loss are < 2 0 10.20.3.173 Tue Nov 06 13:07:32 2007
-
Packets loss are > 2: 100 11.11.11.11 Tue Nov 06 13:11:21 2007
-
Packets loss are > 2: 10 10.20.0.246 Tue Nov 06 13:12:18 2007
-
Packets loss are > 2: 100 1.2.3.4 Tue Nov 06 13:15:57 2007
-
Packets loss are < 2 0 10.20.3.173 Tue Nov 06 13:16:36 2007
-
Packets loss are > 2: 100 11.11.11.11 Tue Nov 06 13:20:25 2007
-
Are this your current validators? -
def validIP(ipAdd):
-
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(ipAdd)
-
-
def validIP1(ipAdd1):
-
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(ipAdd1)
Which one are you using?
Hi Bartonc,
I use only the first one: -
def validIP(ipAdd):
-
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(ipAdd)
-
but I think the problem is located more at the filter level:
what I want, is the primary ip to be ping and if the packet lost are more than 2%, I want ALL my secondaries IP to be ping even if they are under 2% packet lost. (but I want all the secondaries IP over 2% packet lost to go to my file: myprimarylogs.txt). Actually the present script stop pinging as soon as one of the secondaries IP are over 2 % packet lost and go back to ping my primary, it does not ping all the way down all the secondaries IPs. What do you suggest ?
Hi,
any suggestion ?
Brgds/Charlie
bvdet 2,851
Expert Mod 2GB
Hi,
any suggestion ?
Brgds/Charlie
Your problem can be corrected by modifying the code in function ping(). When fil() returns True, the 'break' statement breaks out of the for loop. You will need a way of continuing the for loop even though fil() returns True for the secondary IPs. HTH
Sign in to post your reply or Sign up for a free account.
Similar topics
by: john.livermore |
last post by:
Quick question about deleting data from SQL Server.
We have a table that gets quite a bit of activity with an attribute of
type text (inserts that store new text entries of 50-200k apiece)....
|
by: Burkhard Schultheis |
last post by:
As I wrote last week, we have a problem with a DB2 V8 on Linux. Here is
what is in db2diag.log during online backup:
Starting a full database backup.
2004-04-01-02.33.54.760164 ...
|
by: uthuras |
last post by:
Machine : AIX 5.2
Product : UDB DB2 Release 8.1 FP4a
I have problem loading data into destination table. The data file is
huge with more than 6 Million records. This what i have done
1....
|
by: bil.shah |
last post by:
Hi,
I am listening to a port for data but I am not able to recieve whole
data, I only get truncated data. Client sends me data that exceeds 40K
and the data I recieve in my callback function is...
|
by: David A. Schramm |
last post by:
I am using OLE DB in .NET 2 to insert a row into an Access database. The
source is a RTF control and the column is a Memo field. The data is being
truncated along the way. The control's rtf...
|
by: Grip |
last post by:
Hi,
I have gone throught the group and Microsoft's online help and have
seen many suggestions but I am still seeking clarity:
1. I have an excel spreadsheet. Column A contains text that may...
|
by: Coldfire |
last post by:
i am having error ....details are
ASP.Net application...in which I have a textbox
<asp:TextBox ID="Other" TextMode=SingleLine CssClass="serviceBox" Width="250" Height="45" Runat="server"...
|
by: Kenevel |
last post by:
Hi there,
I'm trying to track down the log file into which the following failure
will be written.
---
SQL4302N Procedure or user-defined function
"SRCPROD.PRO_GENERATE_GROUP_EVENTS",...
|
by: Larry Bates |
last post by:
Every time I look at the logging module (up until now) I've given up and
continue to use my home-grown logger that I've been using for years. I'm not
giving up this time ;-)
I find that I...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM).
In this month's session, the creator of the excellent VBE...
|
by: MeoLessi9 |
last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
|
by: Aftab Ahmad |
last post by:
Hello Experts!
I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: marcoviolo |
last post by:
Dear all,
I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
| |