Sponsored Content
Full Discussion: Nmap PHP FE
Top Forums Shell Programming and Scripting Nmap PHP FE Post 39313 by norsk hedensk on Wednesday 13th of August 2003 12:45:29 AM
Old 08-13-2003
ah what the hell ill post it. all comments are stripped from the script to save space, everything is very self explanitory as this is very basic.

serverstatus.sh
Code:
#!/bin/bash
echo "Starting server stat..."

ftp_func2 ()
{
if  echo $a | grep 21 > /dev/null
then
	echo "ftp is running"
else
	echo "ftp is not running"
fi

}

ssh_func2 ()
{
if echo $a | grep 22 > /dev/null
then
	echo "ssh is running"
else
	echo "ssh is not running"
fi

}

fake_func2 ()
{
if echo $a | grep testing > /dev/null
then
	echo "fake service running" # shouldnt be
else
	echo "fake service not running"
fi

}

telnet_func2 ()
{
if echo $a | grep 23 > /dev/null
then
	echo "telnet is running"
else
	echo "telnet is not running"
fi

}

smtp_func2 ()
{
if echo $a | grep 25 > /dev/null
then
	echo "smtp is running"
else
	echo "smtp is not running"
fi

}

http_func2 ()
{
if echo $a | grep 80 > /dev/null
then
	echo "http is running"
else
	echo "http is not running"
fi

}

pop_func2 () # not 2, not 4, but 3
{
if echo $a | grep 110 > /dev/null
then
	echo "pop3 is running"
else
	echo "pop3 is not running"
fi

}
non_interactivemode_func ()
{
	ftp_func2
	ssh_func2
	fake_func2 # this is just to make me feel better
	telnet_func2
	smtp_func2
	http_func2
	pop_func2
}

version_func ()
{
echo "Serverstat 0.9"
echo "Copyright 2003 Joseph Oldak."
echo "This is free software; There is NO warranty; not even for MERCHANTABILITY or"
echo "FITNESS FOR A PARTICULAR PURPOSE.		-taken from GNU grep -V"
echo "This script was written soley for my own use and is extremely simple."
echo "It is more of an exercise for my self to learn BASH shell scripting."

}

help_func ()
{
echo "Serverstat 0.9" 
echo "This script checks to see what services are running on a given host."
echo "You must run serverstat with the -s option to tell it what host to scan."
echo "For now, this script uses nmap, however in the future it wont require it."
echo "The options i or n are required, one or the other."
echo "Example: ./serverstat -si somehostname.com"
echo "-s	Specify hostname, either in dotted quad, or a FQDN."
echo "-i	Interactive mode, select what to check is running."
echo "-n	Non-Interactive mode, scans everything. Mainly for use in other scripts"
echo "-v	Output version information."
echo "-h	Output usage (this help message)."

}
interactivemode_func ()
{
clear

echo "Select which services you wish to check status of  : "; echo $hostname2
echo "1. ftp"; echo "$b"
echo "2. ssh"; echo "$c"
echo "3. telnet"; echo "$e"
echo "4. smtp"; echo "$f"
echo "5. http"; echo "$g"
echo "6. pop3"; echo "$p"
echo "7. exit server status"
echo "select from 1-7"

read option_number

case "$option_number" in

1 )
ftp_func
;;

2 )
ssh_func
;;

3 )
telnet_func
;;

4 )
smtp_func
;;

5 )
http_func
;;

6 )
pop_func
;;

7 )
echo " Quiting ..."
exit 0
;;

* )
echo "please select 1-7"
interactivemode_func
;;
esac
}


main () 
{
NO_ARGS=0
E_OPTERROR=65

if [ $# -eq "$NO_ARGS" ] # should check for no arguments
then
	echo "Usage: `basename $0` -s<OPTIONS> <HOSTNAME> "
	echo "You must specify interactive, or non interactive mode for now"
	echo "Try './serverstatus -h' for more information."
	exit $E_OPTERROR
fi

while getopts ":sinvh" Option
do
	case $Option in

		s )
			hostname=`echo $@`
			hostname2=`echo $hostname|awk '{print $2}'`
			echo $hostname2
			a=`nmap $hostname2`

		;;

		i )
			interactivemode_func
		;;

		n )
			non_interactivemode_func
		;;

		v )
			version_func
		;;

		h )
			help_func
		;;

		* )
			echo "Unimplemented option chosen"
		;;
	esac
done

shift $(($OPTIND - 1))

}

# ok this is retarded ...
ftp_func ()
{
if  echo $a | grep 21 > /dev/null
then
	echo "ftp is running"
	b=`echo ftp is running`
else
	echo "ftp is not running"
	b=`echo ftp is not running`
fi
interactivemode_func
}

ssh_func ()
{
if echo $a | grep 22 > /dev/null
then
	echo "ssh is running"
	c=`echo ssh is running`
else
	echo "ssh is not running"
	c=`echo ssh is not running`
fi
interactivemode_func
}

fake_func ()
{
if echo $a | grep testing > /dev/null
then
	echo "fake service running" # shouldnt be
	d=`echo fake service is running`
else
	echo "fake service not running"
	d=`echo fake service is not running`
fi
interactivemode_func
}

telnet_func ()
{
if echo $a | grep 23 > /dev/null
then
	echo "telnet is running"
	e=`echo telnet is running`
else
	echo "telnet is not running"
	e=`echo telnet is not running`
fi
interactivemode_func
}

smtp_func ()
{
if echo $a | grep 25 > /dev/null
then
	echo "smtp is running"
	f=`echo smtp is running`
else
	echo "smtp is not running"
	f=`echo smtp is not running`
fi
interactivemode_func
}

http_func ()
{
if echo $a | grep 80 > /dev/null
then
	echo "http is running"
	g=`echo http is running`
else
	echo "http is not running"
	g=`echo http is not running`
fi
interactivemode_func
}

pop_func () # not 2, not 4, but 3
{
if echo $a | grep 110 > /dev/null
then
	echo "pop3 is running"
	p=`echo pop3 is running`
else
	echo "pop3 is not running"
	p=`echo pop3 is not running`
fi
interactivemode_func
}

main "$@"

 

9 More Discussions You Might Find Interesting

1. Cybersecurity

Nmap

I am pretty new at running nmap ,and i have some doubt about some o/ps the nmap shows I tried to scan my own system for UDP open ports I see that if i use one UDP port say 13 It shows that its in open state , etc But if i scan for the whole UDP ports in the nmap-services . I gives te... (2 Replies)
Discussion started by: DPAI
2 Replies

2. UNIX for Dummies Questions & Answers

nmap results

Hi, Whenever I tried to run nmap on my linux (red hat 6.2) boxes i got these outputs: 4444/tcp filtered krb524 6666/tcp filtered irc-serv 6699/tcp filtered napster 8888/tcp filtered sun-answerbook Can anybody please... (10 Replies)
Discussion started by: necro
10 Replies

3. AIX

nmap on aix 5.2

I'm trying to compile nmap 4.11 on an aix 5.2 machine and get the following error when attempting the 'make' command; make "Makefile", line 1: make: 1254-055 Dependency line needs colon or double colon operator. "Makefile", line 14: make: 1254-055 Dependency line needs colon or double colon... (2 Replies)
Discussion started by: zuessh
2 Replies

4. Red Hat

To change of port name in nmap

Hi, Is it possible to change the nmap port name: For eg: 21/tcp open ftp 53/tcp open domain 80/tcp open http 111/tcp open rpcbind 836/tcp open unknown 843/tcp open unknown 953/tcp open rndc I need to change the port number 836 unknown to the name of the... (4 Replies)
Discussion started by: gsiva
4 Replies

5. Shell Programming and Scripting

FTP/nmap/.netrc

So... I'm trying to script and FTP Backup of some files from openVMS Alpha machine to a Unixware 7 machine. I decided to use .netrc to do all the FTP actions however when I send the nmap command. It pretty much gets ignored while even other things such "ascii", "case" etc.. get respected... (0 Replies)
Discussion started by: thesubmitter
0 Replies

6. Solaris

Nmap error

I 'm getting following error when i run nmap for an ip .. what could be the reason for it ? #nmap 10.22.67.18 Starting Nmap 4.68 ( Nmap - Free Security Scanner For Network Exploration & Security Audits. ) at 2009-07-06 19:07 UTC Warning: Unable to open interface e1000g3301000 -- skipping it.... (2 Replies)
Discussion started by: fugitive
2 Replies

7. Linux

nmap binaries for linux

Hi , I am exploring the nmap utility for Linux. I know that, nmap binaries are specific to the platforms e.g. nmap binaries will be diferent for Windows , AIX , Solaris and Linux platforms. Can anyone tell me , will the nmap binaries be different for different flavours of Linux such as... (1 Reply)
Discussion started by: jatin56
1 Replies

8. Cybersecurity

Help with NMAP

I'm seeing a persistent address showing up on my firewall router logs. The address is 10.98.115.9:67, and is broadcasting to 255.255.255.255. I know that this would typically signal a BOOTP service, such as a bootp server announcing itself on the network. But I can't isolate which machine it... (3 Replies)
Discussion started by: renoir611
3 Replies

9. Homework & Coursework Questions

How to scan IP range using nmap?

Scripting language : Bash Shell Script 1. problem statement I have to create function in which read IP addresses one by one from one file (iplist.txt) and scan these IP using nmap. This scan IP's output is saved in output.txt file and parse output.txt to save only open ports with particular IP... (3 Replies)
Discussion started by: sk151993
3 Replies
All times are GMT -4. The time now is 06:38 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy