How can I test an outbound connection to an IP add

2019-02-01 11:51发布

OK, we all know how to use PING to test connectivity to an IP address. What I need to do is something similar but test if my outbound request to a given IP Address as well as a specif port (in the present case 1775) is successful. The test should be performed preferably from the command prompt.

标签: ip
6条回答
Melony?
2楼-- · 2019-02-01 12:29

If there is a server running on the target IP/port, you could use Telnet. Any response other than "can't connect" would indicate that you were able to connect.

查看更多
做自己的国王
3楼-- · 2019-02-01 12:31

To automate the awesome service portquiz.net, I did write a bash script :

NB_CONNECTION=10
PORT_START=1
PORT_END=1000

for (( i=$PORT_START; i<=$PORT_END; i=i+NB_CONNECTION ))
do
    iEnd=$((i + NB_CONNECTION))
    for (( j=$i; j<$iEnd; j++ ))
    do
        #(curl --connect-timeout 1 "portquiz.net:$j" &> /dev/null && echo "> $j") &
        (nc -w 1 -z portquiz.net "$j" &> /dev/null && echo "> $j") &
    done
    wait
done
查看更多
放荡不羁爱自由
4楼-- · 2019-02-01 12:34

If you're testing TCP/IP, a cheap way to test remote addr/port is to telnet to it and see if it connects. For protocols like HTTP (port 80), you can even type HTTP commands and get HTTP responses.

eg

Command IP          Port
Telnet  192.168.1.1 80
查看更多
劫难
5楼-- · 2019-02-01 12:35

Here is a small site I made allowing to test any outgoing port. The server listens on all TCP ports available.

http://portquiz.net

telnet portquiz.net XXXX
查看更多
做自己的国王
6楼-- · 2019-02-01 12:38

The bash script example of @benjarobin for testing a sequence of ports did not work for me so I created this minimal not-really-one-line (command-line) example which writes the output of the open ports from a sequence of 1-65535 (all applicable communication ports) to a local file and suppresses all other output:

for p in $(seq 1 65535); do curl -s --connect-timeout 1 portquiz.net:$p >> ports.txt; done

Unfortunately, this takes 18.2 hours to run, because the minimum amount of connection timeout allowed integer seconds by my older version of curl is 1. If you have a curl version >=7.32.0 (type "curl -V"), you might try smaller decimal values, depending on how fast you can connect to the service. Or try a smaller port range to minimise the duration.

Furthermore, it will append to the output file ports.txt so if run multiple times, you might want to remove the file first.

查看更多
小情绪 Triste *
7楼-- · 2019-02-01 12:44

The fastest / most efficient way I found to to this is with nmap and portquiz.net described here: http://thomasmullaly.com/2013/04/13/outgoing-port-tester/ This scans to top 1000 most used ports:

# nmap -Pn --top-ports 1000 portquiz.net

Starting Nmap 6.40 ( http://nmap.org ) at 2017-08-02 22:28 CDT
Nmap scan report for portquiz.net (178.33.250.62)
Host is up (0.072s latency).
rDNS record for 178.33.250.62: electron.positon.org
Not shown: 996 closed ports
PORT     STATE SERVICE
53/tcp   open  domain
80/tcp   open  http
443/tcp  open  https
8080/tcp open  http-proxy

Nmap done: 1 IP address (1 host up) scanned in 4.78 seconds

To scan them all (took 6 sec instead of 5):

# nmap -Pn -p1-65535 portquiz.net
查看更多
登录 后发表回答