-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhostcomplete
executable file
·68 lines (62 loc) · 1.07 KB
/
hostcomplete
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/bash
# FLAG: headupcommands
arg=$1
result=()
lookupWithnmap() {
local interface=`ip address | grep -i "state UP"`
interface=($(echo $interface | tr " " "\n"))
interface=${interface[1]}
interface=${interface//\:/}
regexp="inet (.+?) brd (.+?) $interface"
interface=`ip address | grep -iE "$regexp"`
if [[ $interface =~ $regexp ]];
then
interface=()
interface=${BASH_REMATCH[1]}
interface=`nmap -sL $interface | grep -i "$arg"`
set -f
IFS=$'\t\n'
regexp="scan report for (.+?) \("
for i in ${interface[@]}
do
if [[ $i =~ $regexp ]];
then
local elem=${BASH_REMATCH[1]}
if ! [[ -z "$elem" ]];
then
result+=("$elem")
fi;
fi;
done;
fi;
return 0
}
lookupWitharp() {
local res=`arp | grep -i "$arg"`
set -f
old_ifs=$IFS
IFS=$'\t\n'
for i in ${res[@]}
do
IFS=$' '
for u in ${i[@]}
do
if ! [[ -z "$u" ]];
then
result+=("$u")
fi
break
done
IFS=$'\t\n'
done
}
if ! [ -z $(which arp) ];
then
lookupWitharp
#echo "hi"
elif ! [ -z $(which nmap) ];
then
#echo "blib"
lookupWithnmap
fi;
echo ${result[*]}