2

I have a program that i have wrote, internally i am using the Fping program in order to send pings to other computers, the Fping program needs to get a file that includes a list of IP address in order to get Fping to send pings automatically to a bunch of IP address.

Right now in my script i am creating a file on the disk then call Fping to use that file, then i am deleting the file.

I would like to know if there is a way to create a file-like object that is acting as a file, then i could call Fping to use that object instead of a real file.

I am using Python 3, and Fping for Windows.

Thanks.

Hanan
  • 1,169
  • 3
  • 23
  • 40

2 Answers2

2

Because fping can read in the list of machines from standard input (see details in the man page) you simply need to write the addresses to standard input. The subprocess module can provide some ways to write data to standard input, but if all the data is known at the start, a (somewhat tacky) way to do this is to add echo to your command.

echo 4.2.2.1 www.google.com www.yahoo.co.uk | fping
sarnold
  • 102,305
  • 22
  • 181
  • 238
  • I am using Fping for Windows, can i assume that it has the ability to read a list of IPs from the stdin too ? – Hanan Mar 14 '12 at 08:49
  • Hrm, if it is the same project, then yes, but if it is supplied by a different group, then maybe not. Try it and see? (If it isn't, please respond again, and I can delete my answer.) – sarnold Mar 14 '12 at 08:51
2

Do you have to use Fping? You could ping directly from python.

Ping a site in Python?

Community
  • 1
  • 1
Lennart Regebro
  • 167,292
  • 41
  • 224
  • 251