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.
$ 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):
<?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:
thanks danx10 that works perfectly and is just what I needed! I like how you referenced the variables to php site. xtra thanks