# Linux下检测某个ip端口的连通状态


举个例子，要测试的 ip+port: 192.168.0.100:8080

1. 使用 `telnet` 命令

    `telnet 192.168.0.100 8080`

    连通成功：

    ```
    Trying 192.168.0.100...
    Connected to 192.168.0.100.
    Escape character is '^]'.
    Connection closed by foreign host.
    ```

    连通失败：
    ```
    rying 192.168.0.100...
    telnet: Unable to connect to remote host: Connection refused
    ```

2. 使用 `nc` 命令

    `nc -zvw3 192.168.0.100 8080`

    参数说明：
    1. `-z`: 仅扫描侦听， 不会发送数据。
    2. `-v`: 输出详细信息。
    3. `-w3`: 允许超时3秒~

    连通成功：
    
    ```
    Connection to 192.168.0.100 8080 port [tcp/http] succeeded!
    ```

    连通失败：
    ```
    nc: connect to 192.168.0.100 port 8080 (tcp) failed: Connection refused
    ```

3. 使用 `nmap` 命令
    
    `nmap 192.168.0.100 -p 8080`

    连通成功：
    ```
    Starting Nmap 7.80 ( https://nmap.org ) at 2021-01-21 21:30 CST
    Nmap scan report for 192.168.0.100
    Host is up (0.00049s latency).

    PORT     STATE SERVICE
    8080/tcp open  http

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

    连通失败：
    ```
    Starting Nmap 7.80 ( https://nmap.org ) at 2021-01-21 21:30 CST
    Nmap scan report for 192.168.0.100
    Host is up (0.00029s latency).

    PORT     STATE  SERVICE
    8080/tcp closed unknown

    Nmap done: 1 IP address (1 host up) scanned in 0.06 seconds
    ```
---
欢迎访问 `spaceack.com`
