Skip to content

Instantly share code, notes, and snippets.

@mmasko
Last active October 14, 2025 17:29
Show Gist options
  • Save mmasko/ec5bf846c24ce1dee283a11fcc8e3fbe to your computer and use it in GitHub Desktop.
Save mmasko/ec5bf846c24ce1dee283a11fcc8e3fbe to your computer and use it in GitHub Desktop.
port check on linux using raw shell
# Linux
true &>/dev/null </dev/tcp/$HOSTNAMEorIP/$PORT && echo open || echo closed
# Ansible
ansible all -m win_ping -i $IP, --extra-vars "ansible_user=$username ansible_password=$password ansible_port=5986 ansible_connection=winrm ansible_winrm_server_cert_validation=ignore"
# Powershell
$host="<hostname or IP>";$port=<port>;if(Test-NetConnection -ComputerName $host -Port $port -InformationLevel Quiet){Write-Output "open"}else{Write-Output "closed"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment