Script to find ips from a text file (not working)

Discussion in 'PHP' started by insom, Mar 21, 2010.

  1. #1
    I have a set of domains (100+ inserted into a text file (like below) which I would like to get output the ip addresses associated with the domain name.

    http://www.hippocampe.info/
    http://www.highlighthealth.info/
    http://www.helpindex.co.uk/
    ...

    Here is what I've done so far but its not working so well..


    
    <?php
    $myFile = ("http://automax.tv/1000-3000.txt");
    $handle = fopen("http://automax.tv/1000-3000.txt","r");
    $data = fgets($handle);
    $ip = rtrim(`/usr/bin/dig -4  $data +short`);
    echo  $ip;
    fclose($handle);
    ?>
    Code (markup):
    However its printing out the full dig without +short and not printing out the ip either.
    http://www.automax.tv/checkip2.php
    I need it to output every domain also.

    If you enter dig -4 +short www.hippocampe.info it should give just the ip...

    any ideas.
     
    insom, Mar 21, 2010 IP
  2. krsix

    krsix Peon

    Messages:
    435
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #2
    
    $ cat test.php
    <?php
    $s = "http://www.hippocampe.info/
    http://www.highlighthealth.info/
    http://www.helpindex.co.uk/";
    $s = str_replace('/','',$s); $s = str_replace('http:','',$s); $l = explode("\n",$s);
    foreach ($l as $h) {
       echo gethostbyname($h)."\n"; // change to echo $h.'  '.gethostbyname($h)."\n"; if you want to show the domain too
    }
    ?>
    
    Code (markup):
    
    $ php test.php
    91.186.0.7
    69.163.230.6
    87.117.195.168
    
    Code (markup):
     
    krsix, Mar 21, 2010 IP
  3. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #3
    <?php
    
    $file = file_get_contents('http://automax.tv/1000-3000.txt');
    
    $lines = str_replace(array("\r\n", "\r"), "\n", $file);
    
    $urls = explode("\n", $lines);
    
    foreach($urls as $url){
    
    echo $url." - ".gethostbyname($url)."<br>";
    }
    
    ?>
    PHP:
     
    danx10, Mar 21, 2010 IP
  4. insom

    insom Well-Known Member

    Messages:
    262
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    108
    #4
    thanks danx10 that works perfectly and is just what I needed! :)
    I like how you referenced the variables to php site.

    xtra thanks :)
     
    insom, Mar 21, 2010 IP