Skip to content

Instantly share code, notes, and snippets.

@Bo0oM
Created July 17, 2020 12:47
Show Gist options
  • Save Bo0oM/2392da86745b01e4a0601e39cb1b1246 to your computer and use it in GitHub Desktop.
Save Bo0oM/2392da86745b01e4a0601e39cb1b1246 to your computer and use it in GitHub Desktop.
p0f-mtu client
<?php
/*
a – string which is NUL-padded
A – string which is SPACE-padded
h – low nibble first Hex string
H – high nibble first Hex string
c – signed character
C – unsigned character
s – signed short (16 bit, machine byte order)
S – unsigned short ( 16 bit, machine byte order)
n – unsigned short ( 16 bit, big endian byte order)
v – unsigned short ( 16 bit, little endian byte order)
i – signed integer (machine dependent byte order and size)
I – unsigned integer (machine dependent byte order and size)
l – signed long ( 32 bit, machine byte order)
L – unsigned long ( 32 bit, machine byte order)
N – unsigned long ( 32 bit, big endian byte order)
V – unsigned long ( 32 bit, little endian byte order)
f – float (machine dependent representation and size)
d – double (machine dependent representation and size)
x – NUL byte
X – Back up one byte
Z – string which is NUL-padded
@ – NUL-fill to absolute position
*/
function p0f_client($ip, $socket)
{
if ($socket = @fsockopen('unix://'.$socket))
{
$query = pack('Lha*@24',0x50304601, 4, inet_pton($ip));
fwrite($socket, $query);
$resp = fread($socket, 249);
fclose($socket);
$resp = unpack( 'Lmagic_number/Lstatus/Lfirst_seen/Llast_seen'.
'/Ltotal_conn/Luptime_min/Lup_mod_days/Llast_nat'.
'/Llast_chg/Sdistance/Cbad_sw/Cos_match_q'.
'/A32os_name/A32os_flavor/A32http_name/A32http_flavor'.
'/smtu/A32link_type/A32language', $resp);
if (!is_array($resp)) {
return false;
}
return $resp;
}
return false;
}
$out = json_encode(p0f_client($_SERVER['REMOTE_ADDR'], '/opt/p0f/p0f.sock'));
print_r($out);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment