Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple SMTP auth test
<?php declare(strict_types=1);
function connect(string $user, string $pass)
{
$host = '192.168.0.147';
$errno = $errstr = null;
if (!($socket = fsockopen($host, 587, $errno, $errstr, 15))) {
die("Failed to connect to $host");
}
server_parse($socket, '220');
fwrite($socket, "EHLO randohost\r\n");
server_parse($socket, '250');
fwrite($socket, 'AUTH LOGIN' . "\r\n");
server_parse($socket, '334');
fwrite($socket, base64_encode($user) . "\r\n");
server_parse($socket, '334');
fwrite($socket, base64_encode($pass) . "\r\n");
if (server_parse($socket, '235')) {
echo "Found a match! $user:$pass\n";
}
fwrite($socket, 'QUIT' . "\r\n");
fclose($socket);
return true;
}
//Functin to Processes Server Response Codes
function server_parse($socket, $expected)
{
$server_response = '';
do {
if (!($server_response = fgets($socket, 256))) {
die('Error while fetching server response codes. Expected: ' . $expected);
}
} while ($server_response[3] !== ' ');
return strpos($server_response, $expected) === 0;
}
$usage = getrusage();
connect("foo", "bar");
$finusage = getrusage();
foreach ($usage as $k => $v) {
echo "$k: ", ($finusage[$k] - $v), "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.