Advertisement
Guest User

ip match

a guest
Feb 26th, 2016
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.66 KB | None | 0 0
  1. <?php
  2.  
  3. function lget($filename)
  4. {
  5.     $handle = fopen($filename, 'r');
  6.     while (FALSE !== $line = fgets($handle)) {
  7.         yield $line;
  8.     }
  9.     fclose($handle);
  10. }
  11.  
  12. $map = [
  13.     ['file' => '1.txt', 'res' => 'Valid'],
  14.     ['file' => '2.txt', 'res' => 'Invalid'],
  15.     ['file' => '3.txt', 'res' => 'Fix'],
  16. ];
  17.  
  18. $targetIP = '1.1.1.1';
  19.  
  20. foreach ($map as $item) {
  21.     $entries = lget($item["file"]);
  22.     $found = FALSE;
  23.     foreach ($entries as $entry) {
  24.         if (strcmp(trim($entry), $targetIP) === 0) {
  25.             echo $item["res"];
  26.             $found = FALSE;
  27.             break;
  28.         }
  29.     }
  30.     if ($found) {
  31.         break;
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement