Year of Python (YOP) – Week Seven


Hello readers!

This week I needed to create a script to scan some servers in my environment to confirm that an agent we deployed was installed.  I could use the “native” client that comes with the agent to do my check, but this gave me an opportunity to write some code.  Plus it would be faster because I just needed to see if I could connect to the port.  That would tell me if the agent is running.

So this “introduced” me to the socket module with Python.  And after a bit of trial and error I got the program to do what I wanted to do.  But I wanted to add some additional aspects that would give me a bit of flexibility with the script.  Mainly that I could just feed it a list of IP’s, pick whatever port I wanted to use, and then output it to a file so I could review the results.

Argparse is the module to use (from what I’ve seen) if you want to pass command line arguments to your program.  The bonus is that it’s already part of any newer python install.  Adding options for the input file, output file, and port means I can basically use the script for this one project, but easily use it for anything else to check in the future.

Until next week!


No Responses Yet to “Year of Python (YOP) – Week Seven”

  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: