;超级简单多线程TCP服务器开放端口扫描器
;无名侠
;2015.5.23
.386
.model flat,stdcall
option casemap:none
include ws2_32.inc
include user32.inc
include kernel32.inc
include windows.inc
include masm32.inc
include msvcrt.inc
includelib msvcrt.lib
includelib ws2_32.lib
includelib user32.lib
includelib kernel32.lib
includelib masm32.lib
;###############################################
;数据段
;###############################################
.data
szInitError db '加载套接字库失败!',0
;====================================用户配置区==============================================
;设置扫描IP
szIp db '127.0.0.1',0
;设置扫描范围
start_port equ 20
end_port equ 2000
;=============================================================================================
Myinfo db '-- 超级简单多线程TCP服务器开放端口扫描器 --',0dh,0ah,'made in China.....',0dh,0ah,0
format1 db '开放TCP端口:%d',0dh,0ah,0
ScannerIp DWORD ?
;###############################################
;代码段 A lovely girl named mooncake.
;###############################################
.code
Thread_scanner proc _port:dword
LOCAL @address:sockaddr_in
LOCAL @h_sock:dword
invoke RtlZeroMemory,addr @address,sizeof @address
invoke socket,AF_INET,SOCK_STREAM,0
cmp eax,INVALID_SOCKET
je _exit
mov @h_sock,eax
;初始化地址信息
invoke htons,_port
mov @address.sin_port,ax
mov @address.sin_family,AF_INET
mov eax,ScannerIp
mov @address.sin_addr,eax
invoke connect,@h_sock,addr @address,sizeof @address
.if eax==0
invoke crt_printf,addr format1,_port
;mov esi,offset OpenPortMap
;mov edi,_port
;mov byte ptr[esi+edi],1
.endif
invoke closesocket,@h_sock
_exit:
ret
Thread_scanner endp
main proc
LOCAL @wsadata:WSADATA
;来点广告信息吧~亲。
invoke crt_printf,addr Myinfo
;初始化套接字库
invoke RtlZeroMemory,addr @wsadata,sizeof @wsadata
invoke WSAStartup,202h,addr @wsadata
;初始化扫描IP
invoke inet_addr,addr szIp
mov ScannerIp,eax
;启动扫描线程
mov ecx,end_port-start_port
loop1:
push ecx
invoke CreateThread,NULL,0,offset Thread_scanner,ecx,0,NULL
pop ecx
loop loop1
invoke crt_getchar
ret
main endp
start:
invoke main
invoke ExitProcess,1
end start