Skip to content

Instantly share code, notes, and snippets.

@zhengxiaowai
Last active December 4, 2016 05:58
Show Gist options
  • Save zhengxiaowai/050adbe8c5bf0eedc1efe4950036e60e to your computer and use it in GitHub Desktop.
Save zhengxiaowai/050adbe8c5bf0eedc1efe4950036e60e to your computer and use it in GitHub Desktop.
扫描已经使用的端口
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import socket
def scan_port(port_num, host):
s = socket.socket()
socket.setdefaulttimeout(2)
try:
s = s.connect((host, port_num))
print port_num, "[+] has used"
except Exception, e:
pass
if __name__ == '__main__':
try:
max_port_numbers = int(sys.argv[1])
except IndexError:
max_port_numbers = 65536
max_port_numbers = max_port_numbers if max_port_numbers <= 65536 else 65536
host = 'localhost'
for i in xrange(max_port_numbers):
scan_port(i, host)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment