Skip to content

Instantly share code, notes, and snippets.

@msoranno
Last active April 18, 2018 08:40
Show Gist options
  • Save msoranno/3d4439bee5938c3993dc541d2299f157 to your computer and use it in GitHub Desktop.
Save msoranno/3d4439bee5938c3993dc541d2299f157 to your computer and use it in GitHub Desktop.
test port no telnet
# test port when no telnet
#/dev/tcp/host/port
# If host is a valid hostname or Internet address, and port is an integer port number
# or service name, bash attempts to open a TCP connection to the corresponding socket.
#/dev/udp/host/port
# If host is a valid hostname or Internet address, and port is an integer port number
# or service name, bash attempts to open a UDP connection to the corresponding socket.
cat < /dev/tcp/127.0.0.1/22
Python (si devuelve 1 hay conexión.)
Python 2.7.5 (default, Aug 4 2017, 00:39:18)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import socket
>>> clientsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>>> clientsocket.connect(('smtp.office365.com', 587))
>>> clientsocket.send('\n')
1
Netcat:
nc -zv -w 5 127.0.0.1 22
Connection to 127.0.0.1 22 port [tcp/ssh] succeeded!
$ nc -zv -w 5 127.0.0.1 23
nc: connect to 127.0.0.1 port 23 (tcp) failed: Connection refused
curl:
$ curl -v telnet://127.0.0.1:22
* About to connect() to 127.0.0.1 port 22 (#0)
* Trying 127.0.0.1... connected
* Connected to 127.0.0.1 (127.0.0.1) port 22 (#0)
SSH-2.0-OpenSSH_5.3
^C
$ curl -v telnet://127.0.0.1:23
* About to connect() to 127.0.0.1 port 23 (#0)
* Trying 127.0.0.1... Connection refused
* couldn't connect to host
* Closing connection #0
curl: (7) couldn't connect to host
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment