473,465 Members | 1,917 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

help index error

29 New Member
when I run program below I am getting an index error on line 18
chk2 = .......
indexerror : list index out of range
Any help appreciated
Thx
Expand|Select|Wrap|Line Numbers
  1. import os
  2. import string
  3. import sys
  4. import linecache
  5.  
  6. ping_results = []
  7. ip_array = ('192.168.1.43', '192.168.1.1', '127.0.0.1')
  8. for ip in ip_array:
  9.     f = os.popen('ping %s' % (ip)).read()
  10.     out_ping = [item.strip() for item in f.splitlines(True)
  11.         if item.strip()]
  12. #f.close()
  13.  
  14. ping_results.append(out_ping)
  15.  
  16. for result in ping_results:
  17.     chk1 = result[4]
  18.     chk2 = int(''.join([s for s in result[8].split() [-1]
  19.     if s.isdigit()]))
  20.     if chk1.startswith("Reply") and chk2 < 80:
  21.             print chk1
  22.             print result[8]
Apr 18 '09 #1
2 2283
bvdet
2,851 Recognized Expert Moderator Specialist
Please use code tags. See "How to ask a question" in Posting Guidelines. When a ping request makes no connection, the data returned looks like this:
Expand|Select|Wrap|Line Numbers
  1. >>> result
  2. ['Pinging 192.168.1.43 with 32 bytes of data:', 'Request timed out.', 'Request timed out.', 'Request timed out.', 'Request timed out.', 'Ping statistics for 192.168.1.43:', 'Packets: Sent = 4, Received = 0, Lost = 4 (100% loss),']
  3. >>> 
Since there are only 7 items in the list, attempting to access the item at list index 8 will produce an IndexError.
Apr 19 '09 #2
dragrid
29 New Member
Bvdet ... Thanks for answering my question - will try to follow posting guideline better ... appreciate the link
Apr 21 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Jean | last post by:
Hi, i'm on windows nt4 sp6a , sql server 7.00.0842 i have something that i don't understand. The table 'source' is taking lot of space but when i bcp out, the file take only 11MB (fixed...
5
by: xuatla | last post by:
Hi, I encountered the following compile error of c++ and hope to get your help. test2.cpp: In member function `CTest CTest::operator+=(CTest&)': test2.cpp:79: error: no match for 'operator='...
5
by: jhon02148 | last post by:
hi this hw have four files: 1. for the main program 2. listp.cpp (the source file) 3. listp.h (the header file) 4. exception.h if there is anybody who could help me with this hw i really...
1
by: jhon02148 | last post by:
hi this hw have four files: 1. for the main program 2. listp.cpp (the source file) 3. listp.h (the header file) 4. exception.h hi iam done with my hw i still have to do one function which is...
1
by: treelife | last post by:
I'm getting and internal server error when | run the following mod_python script. I am actually trying to run Django. Script: from mod_python import apache def handler(req):...
3
by: splintercell | last post by:
well i got this code from java.sun.com and tried modiifying it in all the possible ways,but to no good.. stil its not workin..pleas help me out and try postin good workinw web cralwer if u have.....
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
9
by: weidongtom | last post by:
Hi, I've written the code that follows, and I use the function add_word(), it seems to work fine *before* increase_arrays() is called that uses realloc() to allocate more memory to words. But...
3
by: Stephen Torri | last post by:
Below is a class that is suppose to represent a segment of memory or a contents of a binary image (e.g. ELF executable). I have started to read Modern C++ Design and thought the best way to ensure...
3
by: Dameon99 | last post by:
Hi.. Im experiencing a weird error I dont know how to fix. I have a scanner object and whenever I use nextInt, anything above 3 causes the program to crash saying and links me to this line of the...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.