Skip to content

Instantly share code, notes, and snippets.

@elektrowolle
Last active October 12, 2021 15:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elektrowolle/23c6b43842af99e57d45b59db0a633b3 to your computer and use it in GitHub Desktop.
Save elektrowolle/23c6b43842af99e57d45b59db0a633b3 to your computer and use it in GitHub Desktop.
IP and Port scanner in bash and nc
#!/bin/bash
is_alive_ping()
{
ping -c 1 $1 > /dev/null
local result=$?
local prefix="%s: "
local suffix="\n\x1b[0m"
[ $result -eq 0 ] && printf "$prefix \x1b[32mup$suffix" $1
[ $result -gt 0 ] && printf "$prefix \x1b[31mdown$suffix" $1
}
declare -a ips=( $@ )
for ip in ${ips[@]}
do
is_alive_ping $ip &
done
#!/bin/bash
is_open_nc()
{
local prefix="%s:%s "
local suffix="\n\x1b[0m"
local result="$(echo "\n\n\n" | nc $1 $2)"
[ ${#result} -gt 0 ] && printf "$prefix\x1b[32m open$suffix" $1 $2
[ ${#result} -eq 0 ] && printf "$prefix\x1b[31m closed$suffix" $1 $2
}
declare -a ips=( $@ )
declare -a ports="( $PORTS )"
for ip in ${ips[@]}; do
for port in ${ports[@]}; do
is_open_nc $ip $port &
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment