python - IP address must be specified? -


heres code running in python 2.7 on windows 10

import os  open('test.txt') f:     line in f:          response = os.system("ping -c 1" + line)          if response == 0:                  print(line, "is up!")          else:                  print(line, "is down!") 

the test.txt file contains random ip's, code runs when give out message the ip address must specified. problem don't know how within script. when use regular command promt , ping -c 1 google.com runs through reading text file above python script same google.com needs specified.

q1: mean have ip specified , how it?

q2: should write code in diffrent manner importing different module?

import os  open('test.txt') f:   line in f:    response = os.system("ping -c 1 " + line.strip())    if response == 0:     print(line, "is up!")    else:     print(line, "is down!") 

strip newline off end of records file , add space in ping command.


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -