Skip to content

antony@notes:~/ops-automation$ cat "linux-check-ip.md"

linux check ip

2022-08-10· ops-automation ·Shell Script

linux check ip

#!/bin/bash

for ((n=$1;n<=$2;n=n+1))
do
  if nc -z -w 1 120.96.143.$n 22 &>/dev/null; then
    echo "120.96.143.$n ,22 port existed !"
  else
    echo "120.96.143.$n ,22 port ok !"
  fi
  if nc -z -w 1 120.96.143.$n 80 &>/dev/null; then
    echo "120.96.143.$n ,80 port existed !"
  else
    echo "120.96.143.$n ,80 port ok !"
  fi
  if nc -z -w 1 120.96.143.$n 443 &>/dev/null; then
    echo "120.96.143.$n ,443 port existed !"
  else
    echo "120.96.143.$n ,443 port ok !"
  fi
done