Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

ip address and port check in perl

Posted on 2011-03-04
4
Medium Priority
?
703 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 2000 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

722 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