Skip to content

Instantly share code, notes, and snippets.

@ricardomaia
Created October 19, 2022 17:45
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 ricardomaia/04830eee06119c4ff6c6278801d7d7c3 to your computer and use it in GitHub Desktop.
Save ricardomaia/04830eee06119c4ff6c6278801d7d7c3 to your computer and use it in GitHub Desktop.
Network scan with shell script and www-data user

Network scan with shell script and www-data user

PING IPs

for i in $(seq 1 10); 
  do ping -c1 -t 1 192.168.0.$i | grep -v '100% packet loss' | grep PING | awk '{print $2}' >> /var/www/html/ips.txt; 
  done;

Probe TCP Ports

Lines=$(cat /var/www/html/ips.txt); 
for IP in $IPS; 
  do  for PORT in {1..1000};  
    do echo >/dev/tcp/"$IP"/"$PORT" && echo "$IP:$PORT is open" >> /var/www/html/ports.txt || "$IP:$PORT is closed"; 
    done; 
 done

Embeded into .php file

<?php
set_time_limit(0);
exec('for i in $(seq 1 10); do ping -c1 -t 1 192.168.0.$i | grep -v \'100% packet loss\' | grep PING | awk '{print $2}' >> ips.txt; done;');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment