import socket
import threading # target host address
host = "127.0.0.1"
# thread list
threads = [] def tcp_connect_scan(host, port):
'''
TCP connect scanning
@param host: ip, host name or domain name
@param port: port number
'''
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(1)
result = sock.connect_ex((host, port))
if result == 0:
print("Host {} port {} status open".format(host, port))
else:
print("Host {} port {} status close".format(host, port))
except socket.error as err:
print("{}".format(err))
finally:
sock.close() def tcp_syn_scan(host, port):
'''
TCP SYN scanning
@param host: ip, host name or domain name
@param port: port number
'''
# To be continued
pass def main():
for port in range(0, 65535):
t = threading.Thread(target=tcp_connect_scan, args=(host, port))
threads.append(t)
t.start()
for task in threads:
task.join() if __name__ == '__main__':
main()

Python示例-TCP Port Scan的更多相关文章

  1. python之tcp自动重连

    操作系统: CentOS 6.9_x64 python语言版本: 2.7.13 问题描述 现有一个tcp客户端程序,需定期从服务器取数据,但由于种种原因(网络不稳定等)需要自动重连. 测试服务器示例代 ...

  2. 【Python】TCP Socket的粘包和分包的处理

    Reference: http://blog.csdn.net/yannanxiu/article/details/52096465 概述 在进行TCP Socket开发时,都需要处理数据包粘包和分包 ...

  3. python socket+tcp三次握手四次撒手学习+wireshark抓包

    Python代码: server: #!/usr/bin/python # -*- coding: UTF-8 -*- # 文件名:server.py import socket # 导入 socke ...

  4. 浅谈原始套接字 SOCK_RAW 的内幕及其应用(port scan, packet sniffer, syn flood, icmp flood)

    一.SOCK_RAW 内幕 首先在讲SOCK_RAW 之前,先来看创建socket 的函数: int socket(int domain, int type, int protocol); domai ...

  5. Python Hacking Tools - Port Scanner

    Socket Programming 1.  Scan the target Vulnerable Server. And test it by telnet. 2. Write the scanne ...

  6. Failed to connect to Xilinx hw_server. Check if the hw_server is running and correct TCP port is used.

    Failed to connect to Xilinx hw_server. Check if the  hw_server is running and correct TCP port is us ...

  7. 安装VisualSVN Server 报错The specified TCP port is occupied

    安装过程中报错,如下图所示. The specified TCP port is occupied by another service.Please stop that service or use ...

  8. 【翻译自mos文章】OGG replicat 进程使用的 TCP port

    OGG replicat 进程使用的 TCP port 来源于: TCP PORT USED BY REPLICAT PROCESSES (文档 ID 1060954.1) 适用于: Oracle G ...

  9. python 示例代码1

    第一章 python基础一 ​在此不再赘述为什么学习python这门编程,网上搜索一箩筐.我在此仅说一句python的好,用了你就会爱上它. 本python示例代码1000+带你由浅入深的了解pyth ...

随机推荐

  1. Mysql数据同步Elasticsearch方案总结

    Mysql数据同步Elasticsearch方案总结 https://my.oschina.net/u/4000872/blog/2252620

  2. 红帽Linux故障定位技术详解与实例(3)

    红帽Linux故障定位技术详解与实例(3)   在线故障定位就是在故障发生时, 故障所处的操作系统环境仍然可以访问,故障处理人员可通过console, ssh等方式登录到操作系统上,在shell上执行 ...

  3. zrender-部分小知识点集合

    1.存组件元素和取组件元素,会在数据更新时,将存起来的拿出来 在construct(){ this.saveData=[];//先声明一个空的数组 } //存的方法 setSave(ele,i,nam ...

  4. 在CentOS/Windows下配置Nginx(以及踩坑)

    在CentOS/Windows下配置Nginx(以及踩坑) 1. 序言 因为这类文章网上比较多,实际操作起来也大同小异,所以我并不会着重于详细配置方面,而是将我配置时踩的坑写出来. 2. CentOS ...

  5. SAP Diagnostics Agent无法启动

    [问题]SAP Diagnostics Agent无法启动. [现象]Diagnostics Agent安装并没有发生错误,但是打开SAPMMC,Diagnostics Agent(DAA)的Inst ...

  6. Python天天学_02_基础二

    Python_day_02 金角大王:http://www.cnblogs.com/alex3714/articles/5717620.html ------Python是一个优雅的大姐姐 学习方式: ...

  7. CF G. Indie Album AC自动机+fail树+线段树

    这个套路挺有意思的. 把 $trie$ 和 $fail$ 树都建出来,然后一起跑一跑就好了~ #include <queue> #include <cstdio> #inclu ...

  8. 百度之星 初赛三 最短路 2 Dijkstra

    打比赛的时候切的,不过竟然 wa 了 14 次~ 挺简单的,直接在跑 $Dijkstra$ 的时候记录一下路径最大值就好了. #include <bits/stdc++.h> #defin ...

  9. 【Python】爬虫汇总

    主要流程: 获取url下载网页从网页中找寻自己需要的保存(解析+输出)主要概念URL:分大小写统一资源定位符,对可以从互联网上得到的资源的位置和访问方法的一种简洁的表示,是互联网上标准资源的地址.互联 ...

  10. [笔记]makefile编写

    makefile的隐含规则默认处理第一个目标 函数:wildcard可以进行文本匹配 patsubst内容替换 变量: $@代表目标 $^  代表全部依赖 $<  第一个依赖 $?   第一个变 ...