would like to read and parse certain fields from multiple lines ( say lines 5 and 9 and the first and sixth fields respectively)
from the variable of the file the command output created
tried this code below but having problems parsing out_ping -
ip_array = ('192.168.1.1', '192.168.1.1', '124.128.x.x')
-
for i in ip_array:
-
out_ping = os.popen('ping' + ' ' + i, 'r+').read()
-
#sys.stdout.flush()
-
print out_ping
-
-
out_text = ('out_ping',5,9, 'r')
-
for line in out_text:
-
z = line.split()
-
if line 5 z[0] == "Reply" and line 9 z[6] < 80ms:
-
#sys.stdout.writelines(z[2] + reachable + "\n")
-
print z[2] + reachable + "\n"
-
else
-
print "congested"
1 6377 bvdet 2,851
Recognized Expert Moderator Specialist
Your first for loop appears to work OK. Then you create a tuple and iterate on it in another for loop. The first item in the tuple is the string object 'out_ping'. Look at this: - >>> 'out_ping'.split()
-
['out_ping']
-
>>>
The following if statement is indented incorrectly. It only checks the last iteration of the preceding for loop.
Look at the following and see if you can adapt it for your purpose: - import os
-
-
ip_array = ('192.168.1.1',)
-
ping_results = []
-
for ip in ip_array:
-
f = os.popen('ping %s' % (ip), 'r+')
-
out_ping = [item.strip() for item in f.readlines() if item.strip()]
-
f.close()
-
ping_results.append(out_ping)
-
-
for result in ping_results:
-
chk1 = result[4]
-
chk2 = int(''.join([s for s in result[8].split()[-1] if s.isdigit()]))
-
if chk1.startswith("Reply") and chk2 < 80:
-
print chk1
-
print result[8]
-
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: praba kar |
last post by:
Dear all,
I want to parse the system functions output
but I couldn't do it. Kindly assist me in this
task.
eg) bytesused = os.system('du -sh /Users/enmail')
if I print this bytesused variable the output of
bytesused variable is the below
|
by: Jeannie |
last post by:
Hello group!
I'm in Europe, traveling with my laptop, and I don't any compilers
other than Borland C++ 5.5. available. I also don't have any manuals
or help files available. Sadly, more crippling problems! I never used
C++ much, so, I don't remember commands or fuctions well. My questions
are simple. I posted the DOS window output so you can see the Borland
C++ version I am using:
E:\TZ>bcc32 file2
|
by: Johnny Google |
last post by:
Here is an example of the type of data from a file I will have:
Apple,4322,3435,4653,6543,4652
Banana,6934,5423,6753,6531
Carrot,3454,4534,3434,1111,9120,5453
Cheese,4411,5522,6622,6641
The first position is the info (the product) I want to retreive for the
corresponding code. Assuming that the codes are unique for each product
and all code data is on one line.
|
by: AdrianH |
last post by:
Assumptions
I am assuming that you know or are capable of looking up the functions I am to describe here and have some remedial understanding of C++ programming.
FYI
Although I have called this article “How to Parse a File in C++”, we are actually mostly lexing a file which is the breaking down of a stream in to its component parts, disregarding the syntax that stream contains. Parsing is actually including the syntax in order to make...
|
by: AdrianH |
last post by:
Assumptions
I am assuming that you know or are capable of looking up the functions I am to describe here and have some remedial understanding of C programming.
FYI
Although I have called this article “How to Parse a File in C++”, we are actually mostly lexing a file which is the breaking down of a stream in to its component parts, disregarding the syntax that stream contains. Parsing is actually including the syntax in order to make...
| |
by: qazwart |
last post by:
I am reading from a "cvs rlog" command, and I need both the STDOUT and
STDERR. Unfortunately, something very strange is happening. If I do
this:
$cmd = "$cvs_cmd -q rlog -NS -r$from_label::$to_label neo 2>&1"; //
Hard coded module
DEBUG ("if (!($cvs_fh = popen(\"$cmd\", 'r'))) {");
if (!($cvs_fh = popen("$cmd", 'r'))) {
generate_error("Canot open command \"$cmd\" for reading");
}
|
by: Lawrence Krubner |
last post by:
Imagine a template system that works by getting a file, as a string, and
then putting it through eval(), something like this:
$formAsString = $controller->command("readFileAndReturnString", $formName);
// 06-22-07 - the next commands try to import all the functions that the
|
by: Leighya |
last post by:
Im currently working on this xml file but when i load it to Mozilla, i got an error
"Error Loading Stylesheet: Xpath parse failure: invalid variable name"
It loads on IE properly. Only with the mozilla browser i get an error.
Would someone help me pls.
Here is the code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"...
|
by: bonneylake |
last post by:
Hey Everyone,
Well i am having a problem outputting for my report and hoping someone can explain what i am doing wrong.
What the report is about is comparing my company's part price's to d and h, synnex and techdata. What i was told to do was take are part numbers and combine them with d and h, synnex and techdata to display only one column of parts (did this). Then i was told to create a cfloop using the query i created to combine the...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |