Created
March 8, 2026 07:17
-
-
Save ABB00717/b6c969fa69e9fc39cce9384010388861 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #!/bin/bash | |
| NETWORK="192.168.1.0/24" | |
| USER="user" | |
| # Don'n scan the host | |
| MY_IP=$(hostname -I | awk '{print $1}') | |
| echo "[*] Scanning $NETWORK..." | |
| # -oG (Grepable) Format, so the IP addr is at $2 steadily | |
| IP_LIST=$(sudo nmap -sn $NETWORK -oG - | awk '/Up$/ {print $2}') | |
| for IP in $IP_LIST; do | |
| if [[ "$IP" == "192.168.1.1" ]] || [[ "$IP" == "$MY_IP" ]]; then | |
| continue | |
| fi | |
| echo "[+] Trying to connect to : $IP" | |
| # -o BatchMode=yes: If need password to login, skip it (good for automation) | |
| # -o StrictHostKeyChecking=no: Accept Host Key | |
| ssh -o ConnectTimeout=7 \ | |
| -o BatchMode=yes \ | |
| -o StrictHostKeyChecking=no \ | |
| "$USER@$IP" \ | |
| "hostname; uptime" # If success, execute `hostname` command | |
| if [ $? -eq 0 ]; then # If the command executed | |
| echo "[!] Login Success $IP" | |
| else | |
| echo "[-] Can't login $IP" | |
| fi | |
| echo "--------------------------" | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment