-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
multish-discover-hosts - search for devices in network
New option in multish to collect devices with 22 open port Only put example in /etc/multish/group if directory empty
- Loading branch information
Showing
7 changed files
with
93 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
Package: multish | ||
Version: 0.2.1 | ||
Version: 0.3.0 | ||
Architecture: all | ||
Maintainer: Raul Tierno<[email protected]> | ||
Depends: tmux,sshpass | ||
Depends: tmux,sshpass,nmap | ||
Description: multish allows you to connect and act in multiple ssh connection simultaneously |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/bin/bash | ||
# file name preinst | ||
|
||
echo "Pre Installation code here ..." | ||
|
||
|
||
function createFolderIfNotExists { | ||
if [ ! -d $1 ]; then | ||
mkdir -p $1 | ||
fi | ||
} | ||
|
||
function checkifDirectoryIsEmpty { | ||
if [ -z "$(ls -A $1)" ]; then | ||
echo "The directory $1 is empty" | ||
cp /usr/share/multish/files/example $1/example | ||
else | ||
echo "The directory $1 is not empty. No Action" | ||
fi | ||
} | ||
|
||
FOLDER="/etc/multish/group" | ||
createFolderIfNotExists $FOLDER | ||
checkifDirectoryIsEmpty $FOLDER |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
# multissh - create a tmux-cssh connection from parameter or selected option | ||
# | ||
# Authors: Raul Tierno <[email protected]> | ||
# Fernando Lorenzo | ||
# Fernando Lorenzo <[email protected]> | ||
# | ||
# | ||
|
||
|
@@ -39,21 +39,25 @@ function checkargument { | |
} | ||
|
||
function selectoption { | ||
prompt="Select group: " | ||
prompt="Select Option: " | ||
options=( $(find /etc/multish/group -type f -name "*" -print0 | xargs -0) ) | ||
|
||
echo "" | ||
echo "Create a multiple ssh connection to group" | ||
echo "-----------------------------------------" | ||
PS3="$prompt " | ||
|
||
select opt in "${options[@]}" "Copy SSH public key to group" "Quit" ; do | ||
if (( REPLY == 2 + ${#options[@]} )) ; then | ||
select opt in "${options[@]}" "Find hosts with port 22 open in network" "Copy SSH public key to group" "Quit" ; do | ||
if (( REPLY == 3 + ${#options[@]} )) ; then | ||
break | ||
elif (( REPLY == 1 + ${#options[@]} )); then | ||
elif (( REPLY == 2 + ${#options[@]} )); then | ||
echo | ||
multish-copy-id | ||
exit | ||
elif (( REPLY == 1 + ${#options[@]} )); then | ||
echo | ||
multish-discover-hosts | ||
exit | ||
elif (( REPLY > 0 && REPLY <= ${#options[@]} )) ; then | ||
echo "You picked $opt which is file $REPLY" | ||
cssh $opt | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#!/bin/bash | ||
# | ||
# multissh-discovers-hosts - search for devices with 22 open port to store and connect to them | ||
# | ||
# Authors: Raul Tierno <[email protected]> | ||
# | ||
# | ||
|
||
function findAllHostsWithPort22OpenInNetwork { | ||
sudo nmap 192.168.1.1-254 -p22 -oG - | awk '/22\//{print $2 " # " $5}' | ||
} | ||
|
||
function readFromCLIWithDefaultOption { | ||
read -p "$1 [$2]: " result | ||
if [ -z $result ]; then | ||
result=$2 | ||
fi | ||
echo $result | ||
} | ||
|
||
function getSuggestedNetwork { | ||
echo $(ip -4 -o addr | awk ' {print $4}' | grep -v "127.0.0.1" | head -n 1) | ||
} | ||
|
||
function getSuggestedName { | ||
date +"%Y-%m-%d-%H-%M-%S-discover-results" | ||
} | ||
|
||
function createFolderIfNotExists { | ||
if [ ! -d $1 ]; then | ||
mkdir -p $1 | ||
fi | ||
} | ||
|
||
SUGGESTEDNETWORK=$(getSuggestedNetwork) | ||
SUGGESTEDNAME=$(getSuggestedName) | ||
|
||
NETWORK=$(readFromCLIWithDefaultOption "Define la red que quieres explorar" $SUGGESTEDNETWORK) | ||
FILENAME=$(readFromCLIWithDefaultOption "Nombre de archivo donde se guardarán los resultados" $SUGGESTEDNAME) | ||
FOLDER="/etc/multish/group/network-discoveries" | ||
|
||
echo "Explorando $NETWORK. Los resultados se guardarán en $FILENAME. Espere a que termine el proceso..." | ||
|
||
createFolderIfNotExists $FOLDER | ||
|
||
sudo nmap $NETWORK -p22 -oG - | awk '/22\/open/{print "root@" $2 " # " $5}' > $FOLDER/$FILENAME | ||
|
||
echo "Exploración Finalizada. Los resultados se han guardado en $FOLDER/$FILENAME" | ||
|
||
RUN=$(readFromCLIWithDefaultOption "¿Quieres conectarte ahora a los equipos encontrados? y/n " "y") | ||
if [[ $RUN =~ ^[YySs]$ ]] | ||
then | ||
multish "$FOLDER/$FILENAME" | ||
else | ||
multish | ||
fi |
File renamed without changes.