List of IPs & database lookup


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting List of IPs & database lookup
# 1  
Old 03-24-2009
List of IPs & database lookup

I am trying to feed a list of IP's to do lookups from a database. My script works only for the first IP but all subsequent IPs output as 'unknown'.

PHP Code:
#!/usr/bin/php -q
<?
$ip = file('ip.txt');
foreach ($ip as $ip_num => $ip) {
        echo $ip;
        $out=sprintf("%u", ip2long($ip));
        $sql="SELECT country_name FROM geoip WHERE ($out BETWEEN ip_begin AND ip_end)";
        echo $sql;
        $link = mysql_connect('localhost','root','password');
        mysql_select_db('maxmind');
        $query = mysql_query($sql,$link);
        while ($row = @mysql_fetch_array($query,MYSQL_ASSOC)) {
                $data[] = $row;
        }
      if (count($data) == 1) {
                echo $data[0]['country_name']."\n";
      }
      else {
              echo "Unknown\n";
      }
}
?>
Should I be using something else to feed the list of IP's or another kind of loop?

thanks & regards
# 2  
Old 03-24-2009
Dont worry about this. I took out the while loop and its working as expected now.

thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. AIX

Get List of users+IPs

Hello! We have an AIX box (6.3), we are looking for a way to get list of logged in users and their IP. The issue we have is running who -ub shows hostname and we are wanting to get the ip. Any suggestions of ideas? Thanks in advance for any help! (4 Replies)
Discussion started by: entropy1980
4 Replies

2. Shell Programming and Scripting

Grepping a list of words from one file in a master database of homophones

Hello, I am sorry if the title is confusing, but I need a script to grep a list of Names from a Source file in a Master database in which all the homophonic variants of the name are listed along with a single indexing key and store all of these in an output file. I need this because I am testing... (4 Replies)
Discussion started by: gimley
4 Replies

3. Shell Programming and Scripting

Get Ips from a list file

Hi Everyone, I typed a command: awk '{ print $1}' $LOGFILE | sort | uniq -c | sort -nr > $DEST/a.txt And I got file a.txt which show 6 1.1.1.1 3 2.2.2.2 2 3.3.3.3 1 4.4.4.4 Just now, I want to get exact ips which has first column > 5 to a file b.txt. In this situation, the... (5 Replies)
Discussion started by: testcase
5 Replies

4. Shell Programming and Scripting

Filter a list of IPs

Hello, I have a dump of IPs (around 2 million) and i need to filter out(delete) 37 IPs from this list. Here is a short list of IPs that i would need deleted 111.111.xxx.xxx 123.123.xxx.xxx 127.x.x.x 98.20.xx.xxx 10.135.xxx.xxx 11.105.xxx.xx 100.100.xxx.xxx 101.xxx.xx.xxx ... (11 Replies)
Discussion started by: senormarquez
11 Replies

5. Shell Programming and Scripting

Problems using join for simple database lookup

I am trying to get a script working that will perform a simple database lookup using the join command. Here are the two files that I am trying to join: % cat lookup1.txt Number_1 Other_data_a Number_5 Other_data_b Number_8 Other_data_c Number_10 Other_data_d % cat... (2 Replies)
Discussion started by: JasonHamm
2 Replies

6. Shell Programming and Scripting

lookup in a list

I have a list of ids and a master list. I need to display entries from the master list matching ids in the first list. The master list is space delimited, id is 1st field. $ cat id_list 2010 7 51 $ cat master_list 1 one detail1 detail2 2 two detail1 avg1 detail2 avg2 ... etc ... ... (3 Replies)
Discussion started by: migurus
3 Replies

7. UNIX for Advanced & Expert Users

Clueless about how to lookup and reverse lookup IP addresses under a file!!.pls help

Write a quick shell snippet to find all of the IPV4 IP addresses in any and all of the files under /var/lib/output/*, ignoring whatever else may be in those files. Perform a reverse lookup on each, and format the output neatly, like "IP=192.168.0.1, ... (0 Replies)
Discussion started by: choco4202002
0 Replies

8. UNIX for Dummies Questions & Answers

List & While Loop

I want to store a set of string values in a 1-D array and then iterate the list by using a loop. Please help this dummy:) (1 Reply)
Discussion started by: ngagemaniac
1 Replies

9. UNIX for Dummies Questions & Answers

how to list a directory & file

Good day every body, Iv've been given a list of files and directory requested by the Auditor's. My problem is how do i list the file with the permission given and also save the file into text.file so that i can passed the result/oucome to them?? Thanks alot guys!! (2 Replies)
Discussion started by: gagasan_makmur
2 Replies
Login or Register to Ask a Question