[Linux] Test whether the ip:port port is connected to reachability test

【Linux】Testing whether the ip:port port is connected can reachability test
0, background
1, telnet reachability test
2, curl reachability test
3, wget reachability test

0. Background
In the process of visual project development and debugging, it is often necessary to determine whether the IPC is reachable, and it is also necessary to determine whether the server is reachable when doing services.
This blog introduces three commonly used tools (telnet, curl, wget) for reachability testing.

1. Telnet reachability test

  telnet ip port
  • For example: telnet 127.0.0.1 8080

If the telnet connection ip port exists, the following example will appear:

root@s3d-wandev:/home/mysql/mysql_data# telnet 127.0.0.1 8888
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.

If the telnet connection ip port does not exist, the following example will appear:

root@s3d-wandev:/home/mysql/mysql_data# telnet 127.0.0.1 8882
Trying 127.0.0.1...
telnet: Unable to connect to remote host: Connection refused

2. curl reachability test

curl ip:port
  • For example: curl 127.0.0.1:8080
    If the curl connection ip:port exists, the following example will appear:
root@s3d-wandev:/home/mysql/mysql_data# curl 127.0.0.1:8888
<!doctype html><html lang="en"><head><title>HTTP Status 404 – Not Found</title><style type="text/css">h1 {
    
    font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} h2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;

If the curl connection ip:port does not exist, the following example will appear:

root@s3d-wandev:/home/mysql/mysql_data# curl 127.0.0.1:8882
curl: (7) Failed to connect to 127.0.0.1 port 8882: Connection refused

3. wget reachability test

wget ip:port
  • For example: wget 127.0.0.1:8080

If the wget connection ip:port exists, the following example will appear:

root@s3d-wandev:/# wget 127.0.0.1:8888
--2022-12-05 15:12:05--  http://127.0.0.1:8888/
Connecting to 127.0.0.1:8888... connected.
HTTP request sent, awaiting response... 404 
2022-12-05 15:12:05 ERROR 404: (no description).

If the wget connection ip:port does not exist, the following example will appear:

root@s3d-wandev:/# wget 127.0.0.1:8080
--2022-12-05 15:12:00--  http://127.0.0.1:8080/
Connecting to 127.0.0.1:8080... failed: Connection refused.

Guess you like

Origin blog.csdn.net/MortShi/article/details/128182234