"Fossies" - the Fresh Open Source Software Archive 
Member "mosshe/tools/create_mosshe.sh" (11 Mar 2015, 3111 Bytes) of package /linux/privat/old/mosshe.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
1 #!/bin/sh
2 TARGETFILE=$1
3
4 if [ -z "$TARGETFILE" ]; then
5 echo "USAGE: create_mosshe.sh TARGETFILE ip/mask ip/mask ..."
6 exit 0
7 fi
8
9 if [ -f "$TARGETFILE" ]; then
10 echo "target file $TARGETFILE already exists. Aborting."
11 exit 0
12 fi
13
14
15
16
17 #----------------------------------------------
18 SCANRESULT=`mktemp`
19 TMP=`mktemp`
20
21 cp create_mosshe.header $TARGETFILE
22
23 echo " "
24 echo "Scanning pingable Hosts in $2 $3 $4 $5 $6 $7 $8 $9 ..."
25 echo " "
26 nmap -sP -oG $TMP $2 $3 $4 $5 $6 $7 $8 $9 >/dev/null 2>/dev/null
27 fgrep -v "# Nmap " < $TMP | fgrep -v " hosts up " > $SCANRESULT
28
29 echo " " | tee -a $TARGETFILE
30 echo "#-------------------------------- " | tee -a $TARGETFILE
31 echo "# Pingable hosts " | tee -a $TARGETFILE
32 while read LINE; do
33 HOST=`echo $LINE | cut -d "(" -f 2 | cut -d ")" -f 1`
34 if [ -z "$HOST" ]; then
35 HOST=`echo $LINE | cut -d " " -f 2`
36 fi
37 echo "PingPartner $HOST 2 60 250 # IP, NumberOfPings, max% Loss, max. Roundtrips " | tee -a $TARGETFILE
38 done < $SCANRESULT
39
40
41 # Host: 127.0.0.1 (localhost.localdomain) Status: Up
42
43
44 echo " "
45 echo " "
46 echo " "
47 echo "Scanning Services in $2 $3 $4 $5 $6 $7 $8 $9 ..."
48 echo " "
49 nmap -sT -sV -p- -oG $TMP $2 $3 $4 $5 $6 $7 $8 $9 >/dev/null 2>/dev/null
50 fgrep -v "# Nmap " < $TMP > $SCANRESULT
51
52 while read LINE; do
53 HOST=`echo $LINE | cut -d "(" -f 2 | cut -d ")" -f 1`
54 if [ -z "$HOST" ]; then
55 HOST=`echo $LINE | cut -d " " -f 2`
56 fi
57 HOST=`echo $LINE | cut -d "(" -f 2 | cut -d ")" -f 1`
58 echo " " | tee -a $TARGETFILE
59 echo "#-------------------------------- " | tee -a $TARGETFILE
60 echo "# $HOST " | tee -a $TARGETFILE
61 PORTLIST=`echo $LINE | cut -d ":" -f 3 | sed -e "s/ //g"`
62
63 PORT=`echo $PORTLIST | cut -d "," -f 1`
64 while [ "$PORT" ]; do
65 PORTLIST=`echo $PORTLIST | cut -d "," -f 2-`
66
67 NUMBER=`echo $PORT | cut -d "/" -f 1`
68 PROTO=`echo $PORT | cut -d "/" -f 3`
69 L7=`echo $PORT | cut -d "/" -f 5`
70
71 if [ "$NUMBER$L7" = "21ftp" ]; then
72 echo "FTPcheck $HOST" | tee -a $TARGETFILE
73 elif [ "$L7" = "ssh" ]; then
74 echo "SSHcheck $HOST $NUMBER" | tee -a $TARGETFILE
75 elif [ "$NUMBER$L7" = "25smtp" ]; then
76 echo "SMTPcheck $HOST" | tee -a $TARGETFILE
77 elif [ "$L7" = "http" ]; then
78 echo "HTTPheader http://${HOST}:${NUMBER}/" | tee -a $TARGETFILE
79 elif [ "$NUMBER$L7" = "110pop3" ]; then
80 echo "POP3check ${HOST}" | tee -a $TARGETFILE
81 elif [ "$NUMBER$L7" = "143imap" ]; then
82 echo "IMAPcheck ${HOST}" | tee -a $TARGETFILE
83 elif [ "$L7" = "rpcbind" ]; then
84 echo "rpcbind on $PROTO/$NUMBER ignored"
85 elif [ "$PROTO" = "tcp" ]; then
86 echo "TCPing $HOST $NUMBER # connect-only = todo: syntax check for protocol $L7" | tee -a $TARGETFILE
87 else
88 echo "# todo: $L7 = $PROTO/$NUMBER" | tee -a $TARGETFILE
89 fi
90
91 PORT=`echo $PORTLIST | cut -d "," -f 1`
92 if [ "$PORT" = "$PORTLIST" ]; then PORT=; fi
93 done
94
95 done < $SCANRESULT
96
97
98 cat create_mosshe.footer >> $TARGETFILE
99 chmod 700 $TARGETFILE
100
101 echo "---------------------------------------------------------------------"
102 echo "Done. Please adapt $TARGETFILE for your configuration."