views:

24

answers:

1

I have a list of IP addresses, about 1300, that I need to look up to find out company information or whatever is available from an online tool. I don't mind if I have to pay for it. but I don't want to have to put each one in manually.

Is there something that I can use that would give me this detail that I could either copy or paste or write a quick script for.

Thanks in advance.

+1  A: 

This would work on Linux or MacOS. If you're on windows, I"m not sure.

<?php
$ip_file=file('/path/to/file');

if($ip_file===false){ echo "file is unreadable\n"; exit; }
if(empty($ip_file)){ echo "file has no contents\n"; exit; }

foreach($ip_file as $line)
  {
   $ip=trim($line);
  if(strlen($ip)>0){
    echo "IP: $ip : ";
    passthru('host '.escapeshellarg(trim($ip)));
    }
  }
Alex JL
`$ip_file` will still be an array if `/path/to/file` is empty. Best to do a `if ($ip_file=file('/path/to/file') { ... }`. Oh, and there's an error on line 4.
amphetamachine
Good point. It's boolean false if the file is unreadable, so we'll check for that, and then use empty() to see if it has content. I've updated the answer. Also, added trim to make it work properly...
Alex JL