Hanan
Hanan

Reputation: 1179

python code instead of a real file

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.

Upvotes: 2

Views: 133

Answers (2)

Lennart Regebro
Lennart Regebro

Reputation: 172309

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

Ping a site in Python?

Upvotes: 2

sarnold
sarnold

Reputation: 104080

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

Upvotes: 2

Related Questions