Advertisement
aaaaaa123456789

Various socket-related PHP functions

Jan 8th, 2014
82
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function get_remote_IP ($socket) {
  2.   $status = socket_getpeerinfo($socket, $result);
  3.   if (!$status) return false;
  4.   return $result;
  5. }
  6.  
  7. function socket_accept_nbl ($listener, $blacklist) {
  8.   $newsocket = socket_accept($listener);
  9.   if ($newsocket === false) return false;
  10.   $ip = get_remote_IP($newsocket);
  11.   if (array_search($ip, $blacklist) !== false) {
  12.     socket_close($newsocket);
  13.     return false;
  14.   }
  15.   return $newsocket;
  16. }
Advertisement
RAW Paste Data Copied
Advertisement