Skip to content

Instantly share code, notes, and snippets.

@vfreex
Created November 20, 2018 09:58
Show Gist options
  • Save vfreex/32b7de2e36422dbee94454afc762305e to your computer and use it in GitHub Desktop.
Save vfreex/32b7de2e36422dbee94454afc762305e to your computer and use it in GitHub Desktop.
Test which TCP ports are blocked by my ISP
#!/bin/bash
for port in {1..9999}; do
echo -n "TCP $port: "
result=$(nc "$1" "$port" -w 1 2>&1 < /dev/null)
if [ "$?" -eq 0 ]; then
echo "Open"
continue
fi
if [[ "$result" == *refused* ]]; then
echo "Closed"
fi
if [[ "$result" == *time* ]]; then
echo "$port" >> block_list.txt
echo "BLOCKED"
fi
done
@malash
Copy link

malash commented Sep 23, 2021

Should add -v on Ubuntu 20.04

diff --git a/scan_isp_blocklist.sh b/scan_isp_blocklist.sh
index c58ba4d..5d394be 100644
--- a/scan_isp_blocklist.sh
+++ b/scan_isp_blocklist.sh
@@ -2,7 +2,7 @@

 for port in {1..9999}; do
   echo -n "TCP $port: "
-  result=$(nc "$1" "$port" -w 1 2>&1 < /dev/null)
+  result=$(nc "$1" "$port" -w 1 -v 2>&1 < /dev/null)
   if [ "$?" -eq 0 ]; then
     echo "Open"
     continue

@izumi-sora
Copy link

怎么调成看开放端口是哪些?

@Diffused7245
Copy link

怎么调成看开放端口是哪些?

这你直接监听所有端口,然后端口扫描就行了,不过Advanced Port Scanner不准。

@lin2yatou
Copy link

多谢脚本,mac系统可以稍微修改下: nc "$1" "$port" -v -G 1 -w 1 2>&1

@nyt35
Copy link

nyt35 commented Aug 13, 2023

大神,本人不才,现在也是遇到了有公网IP但是连接不上的问题,大概率是ISP封锁端口了,通过网上教程找到这里来,冒昧的问一句,这个脚本如何使用?

@bi4nbn
Copy link

bi4nbn commented Jan 30, 2024

冒昧的问一句,这个脚本如何使用?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment