IP list specific port checker script

Hello again people,

I currently searching for a code/script that will allow it to check if a specific port is open, lets say 123. Found a public script on a ftp but I dont know how and what to modify in it to suit my needs. (I think this is a evil code and I want to use it as an example).

cat $1 | while read LN; do
SRV=`echo $LN | awk '{print $1}'`
php connect.php $SRV 123
done

And the file connect.php

<?php

function S_Server($_server, $_port, $_user, $_pass) {
        if ( "$_port" == "123" ) {
                print "[+]Found $_server\r\n";
                if(!($_OutFile = fopen("iplist", "a"))) ExitF ("Cannot open the log file");
                fputs($_OutFile, "$_server $_user $_pass\n");
                fclose($_OutFile);
        }

}

function ExitF($errmsg) {
        print "[-]" . $errmsg . "\r\n";
        exit(0);
}

function CrackSMTP($server, $port, $user, $pass) {
        $socket = fsockopen($server, $port, $errno, $errstr, 2);

        if (!$socket) ExitF ("SOCKET ERROR!");

        fclose($socket);

        S_Server ($server, $port, $user, $pass);

        exit(0);
}

if ($argv[4]) $_PASS = $argv[4];
if (!($_PASS)) $_PASS = "";

if (!($argv[3])) {
        ExitF ("Usage: $argv[0] <hostname> <port> <user> [password]");
}

else {
        CrackSMTP($argv[1], $argv[2], $argv[3], $argv[4]);
}

exit(0);
?>

If the port is open on the specific host to save it in a new file. Also my ip file is line-by-line.

Thank you again.

Galford D. Weller

Did you consider the nc (netcat) tool with its port scanning capabilities?
man nc :

I really wanna use that code as I found it useful and its almost done... but I dont know what to remove from it to suit my needs. I know this is not a coding service and I am willing to show my support and donate a fee... lets say 10$ via PayPal.

This file follow the rules "Don't put all eggs in one basket" :slight_smile:
Is part of a script to bruteforce scan/"crack" an SMTP server but the function called CrackSMTP() is not in the file :cool: