Solved

ip address and port check in perl

Posted on 2011-03-04
4
696 Views
Last Modified: 2013-12-25
I need help in scripting out a multiple ip address and port checking in perl.  The script will read from a  text file with the ip address and port associated with it.  If an ip address and port doesn't work it will create a separate logfile and after all the ip address and port has been checked from the text file, this error logfile with the ip address and port that didn't work will be emailed to me.  Any assistance will be great.  Thanks
0
Comment
Question by:djroh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 8

Accepted Solution

by:
point_pleasant earned 500 total points
ID: 35039764
Give this a try assumes address file is in format of

xxx.xxx.xxx.xxx xx

ip adresss space port

#!/usr/bin/perl

use strict;
use warnings;
use IO::Socket::INET;

my $err_log="/tmp/port_errlog";
open(ERR_LOG, ">$err_log");

while (<>) {
        my ($host, $port) = split / /,$_;
        #Attempt to connect to $host on $port.
        my $socket;
        my $success = eval {
                $socket = IO::Socket::INET->new(
                PeerAddr => $host,
                PeerPort => $port,
                Proto => 'tcp' )
        };
        #If the port was opened, say it was and close it.
        if ($success) {
                shutdown($socket, 2);
        } else {
                chomp ($port);
                print (ERR_LOG "$host $port Failed\n");
        }
}
system ("mail -s "PORT FAILURE ALERT!" your.email@domain.com < /tmp/port_errlog");
~
0
 
LVL 8

Expert Comment

by:point_pleasant
ID: 35039769
sorry usage

perl progname.pl address_file
0
 
LVL 8

Expert Comment

by:point_pleasant
ID: 35039934
sorry usage: perl progname.pl < address_file
0
 

Author Comment

by:djroh
ID: 35043473
Thank you.. I will give it a try.
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
Six Sigma Control Plans

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question