LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   geoiplookup (https://www.linuxquestions.org/questions/linux-software-2/geoiplookup-4175540719/)

ChronicUser 04-25-2015 11:25 AM

geoiplookup
 
Does anyone know how one might pass a list of IP to geoiplookup?

List is either in CIDR notation or in an nmap acceptable format, for example: 10.10.1-10.20-40

michaelk 04-25-2015 02:52 PM

Unless there is some unplublished option there isn't anything in the man pages that indicates it accepts a range of addreses.

ChronicUser 04-25-2015 03:01 PM

I know I took a look in the man pages as well searched for a way on the net.
What people are saying is that there are some workarounds with xargs but than you really need a list of IP addresses one per a line.

Thought I would post a question here and see if someone else would have some different ideas.

Sadly you came to the same conclusion as me... :(

O well no big deal. Could you suggest any alternative command line tools that can do the same job but will accept normal formats of IP addresses ( the ones I listed in the first post ).

corp769 04-25-2015 04:06 PM

Used the following as a reference for the range generation - http://stackoverflow.com/questions/2...f-ip-addresses

Code:

#!/bin/bash

INET_NTOA() {
    local IFS=. num quad ip e
    num=$1
    for e in 3 2 1
    do
        (( quad = 256 ** e))
        (( ip[3-e] = num / quad ))
        (( num = num % quad ))
    done
    ip[3]=$num
    iptemp="${ip[*]}"
    geotemp=$(which geoiplookup)
    echo "$iptemp - $(eval $geotemp "${ip[*]}")"
}

INET_ATON () {
    local IFS=. ip num e
    ip=($1)
    for e in 3 2 1
    do
        (( num += ip[3-e] * 256 ** e ))
    done
    (( num += ip[3] ))
    echo "$num"
}

read -p "Start of IP address range: " ip1
read -p "End of IP address range: " ip2

ip1n=$(INET_ATON $ip1)
ip2n=$(INET_ATON $ip2)

if [[ $ip2n -lt $ip1n ]]; then
    echo "Wrong range: $ip1 - $ip2"
    exit 1;
fi

for ipn in $(seq $ip1n $ip2n)
do
    INET_NTOA $ipn
done

That being said, I slightly edited the one function to do a 'range scan' per say. Of course, modify and have fun with it. Mind you, this is just the simplest bash-script way that I have found. Of course this can be done a few other ways.

Cheers


All times are GMT -5. The time now is 04:44 PM.