Skip to content

Commit

Permalink
Fixing forward and reverse IP lookup. (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
kigster authored Dec 1, 2023
1 parent f8e15cc commit 3890b37
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 13 deletions.
37 changes: 24 additions & 13 deletions lib/user.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,25 +77,36 @@ user.pairs.email() {
}
#———————————————————————————————————————————————————————————————————————————————————————————————————

user.first() {
function user.first() {
user | tr '\n' ' ' | ruby -ne 'puts $_.split(/ /).first.capitalize'
}

# @description Returns the public IP address of your office/station/etc.
# Uses two available methods, more information can be obtained here:
# @see https://apple.stackexchange.com/questions/20547/how-do-i-find-my-ip-address-from-the-command-line
# https://apple.stackexchange.com/questions/20547/how-do-i-find-my-ip-address-from-the-command-line
function user.my.external-ip() {
( curl -s http://checkip.dyndns.org/ | sed 's/[a-zA-Z<>/ :]//g' | sed -E 's/^[\d\.]//g; s/\r//g;' 2>&1 )
}

function user.my.ip() {
local result
result=$(dig +short myip.opendns.com @resolver1.opendns.com)
if [[ -n ${result} ]] ; then
echo "${result}"
else
curl -sSf "http://ipecho.net/plain"; echo
fi
user.my.external-ip | tr -d '\n'
}
#
# https://apple.stackexchange.com/questions/20547/how-do-i-find-my-ip-address-from-the-command-line
function user.my.local-ip() {
ifconfig -l | xargs -n1 ipconfig getifaddr
}

user.my.reverse-ip() {
nslookup "$(user.my.ip)" | grep 'name =' | sedx 's/.*name = //g'
function user.my.reverse-ips() {
local ip="$(user.my.ip)"
local output=$(curl -s "https://api.hackertarget.com/reverseiplookup/?q=${ip}" 2>&1)

if [[ ${output} =~ Membership ]]; then
error "You have exceeded the number of free API calls to determine your reverse IP." \
"Please visit https://hackertarget.com/scan-membership/ if you wish to " \
"increase your limit." >&2
return 1
else
echo
fi
}

user.host() {
Expand Down
9 changes: 9 additions & 0 deletions test/user_test.bats
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ function setup-pairs() {
user.pairs.set-file "test/fixtures/.pairs"
}

@test "user.my.ip" {
set -e
local ip=$( curl -s http://checkip.dyndns.org/ | sed 's/[a-zA-Z<>/ :]//g' | sed -E 's/^[\d\.]//g; s/\r//g;' 2>&1 )
local my_ip=$(user.my.ip)

[[ $my_ip == $ip ]]
}


@test "user.pairs.firstname" {
set -e
setup-pairs
Expand Down

0 comments on commit 3890b37

Please sign in to comment.