Skip to content

Instantly share code, notes, and snippets.

@doublenns
Last active April 11, 2018 14:53
Show Gist options
  • Save doublenns/02f73a83f159461562af75b17b68360e to your computer and use it in GitHub Desktop.
Save doublenns/02f73a83f159461562af75b17b68360e to your computer and use it in GitHub Desktop.
Troubleshooting network connectivity to a port when your Linux machine doesn't have Telnet or Netcat installed
# Check for network port connectivity on remote sys:
TCP_PORT_STATUS=`(echo > /dev/tcp/xx.xx.xx.xx/yyy) >/dev/null 2>&1 && echo "UP" || echo "DOWN"`; echo $TCP_PORT_STATUS
# xx.xx.xx.xx = Destination IP Address
# yyy = Destination Port
Ref: https://superuser.com/a/806331
# Create port listener on local computer using python
#!/usr/bin/env python
import socket
port = yyy
s = socket.socket()
s.bind(("", port))
s.listen(1)
# When you want to close the port listener
s.close()
Ref: https://stackoverflow.com/a/17664210
# `netstat -ln` piped into grep is your friend to see listening ports
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment