My company is renting lot's of IP's. And our clients are mostly mailers. After IP lease, sometimes they make IP's unusable, because IP's gets blocked at certain providers, like Yahoo, Gmail, AOL etc.
Currently, we make a simple check this by binding the IP and running telnet
command from our CentOS systems like the this:
telnet -b $IP smtp.gmail.com 25
And get the output, if it is 220 for OK, or something else that would indicate that IP is not dirty
.
What I am looking for is a PHP script, or first the idea how this can be done. Basically, we would bind IP's, and PHP will check the output of the connection and write to a csv file for example.
I've done lots of php projects in the past, but nothing similar. Any idea from where to start? Thanks for suggestions.
EDIT
Due my investigations, I am able to do something like this,
$eol= system("nc -4 -w 2 -s $Binded_IP smtp.gmail.com 25", $output );
var_dump($output);
and get the output like:
-bash-4.2$ php script.php
220 smtp.gmail.com ESMTP 13sm2795405wml.25 - gsmtp
I am trying with netcat
instead telnet. This is the meaning of the arguments, to those who aren't familiar with netcat:
-4 to bind only IPv4
-s Source IP to bind to
-w 2 Timeout
But the problem is I can not find a way to close that connection, it only hangs out, and remain open. If I find a way to close that connection, I could store $output in the file, filter SMTP status code, and continue with second IP and check it.