Search code examples
linuxbashnetwork-programmingtcpnmap

Checking open ports using ss


I need to check for open ports on linux tcp :80 and tcp :443 in a specified range of addresses 192.168.1.(eg 100-105) and print those with available hosts and ports , I think I've implemented it using nmap and it looks like this:

nmap -sT -p 80, 443 192.168.0.-255

However, I need to use a build-in tool and I decided to do this using ss command. What I wrote so far looks like this :

for i in {0..255}
do
  echo '$i'
  ss -ant '( src 192.168.1.$i or dst 192.168.1.$i ) and ( ( dport = :80 or dport = :443 ) or ( sport = :443 or sport = :80 ) )'
done

But it doesn't work due to the fact the $i variable is placed inside the quotes . I am not sure if I am doing it right, but this is what I managed to do so far.( I'm just a beginner in networking )


Solution

  • I have no access to a linux shell right now, but try with double quotes, like this:

    #!/bin/bash
    
    for i in {0..255}
    do
      echo "$i"
      ss -ant "( src 192.168.1.$i or dst 192.168.1.$i ) and ( ( dport = :80 or dport = :443 ) or ( sport = :443 or sport = :80 ) )"
    done