I'm not sure how large either the text file list or database list is. My thought would be to take the smallest of the two and put all the IPs found in the smaller list in an array.
If the text file is the smaller of the two, then I'd convert the array to a comma delimited list that is ready to be included in a SQL statement.
$IPlist = implode(',', $IParray);
Now you could do something like:
// get IP addresses in the list:
$sql = 'SELECT IPaddress FROM IPListTable WHERE IPaddress IN (' . $IPlist . ')';
// get IP addresses not in the list:
$sql = 'SELECT IPaddress FROM IPListTable WHERE IPaddress NOT IN (' . $IPlist . ')';
If the file list is monster-size, then this may not work so well.
If the database list is the smallest, then load all the IP addresses you have in the database.
Read in the text file line by line and get the IP address. Test if the IP address from the text file is in the array from the database (implement your favorite array searching algorithm here).
I doubt this is the best way of doing it, but its one that comes to mind. If both lists are super-huge and your server doesn't have the RAM memory to store one of the lists in memory, then you may have to resort to some other tricks like reading in one IP address and then querying the database to see if it exists or not and then move on to the next IP in the file - rinse and repeat until you're at the end of the file. Here you just lose a lot of time since for every IP address you have to query the database.
Although, if performance is an issue, you might look into hashing the IP address. I understand databases love hashes...