;本文示例gethost系列函数的用法,如:gethostname,gethostbyname,gethostbyaddr等。
;不足之处,敬请指导。
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;gethostname.asm
.386
.model flat,stdcall
option casemap:none
include windows.inc
include kernel32.inc
include user32.inc
include WS2_32.inc
;不足之处,敬请指导。
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;gethostname.asm
.386
.model flat,stdcall
option casemap:none
include windows.inc
include kernel32.inc
include user32.inc
include WS2_32.inc
includelib user32.lib
includelib kernel32.lib
includelib WS2_32.lib
includelib kernel32.lib
includelib WS2_32.lib
.data
correy db "made by correy",0
correy db "made by correy",0
.data?
lpWSAData WSADATA <>
buffer db 256 DUP (?)
lpWSAData WSADATA <>
buffer db 256 DUP (?)
.code
start:
invoke WSAStartup,2,addr lpWSAData
start:
invoke WSAStartup,2,addr lpWSAData
invoke gethostname,addr buffer,256
invoke MessageBox,0,addr buffer,addr correy,0
invoke MessageBox,0,addr buffer,addr correy,0
invoke WSACleanup
invoke ExitProcess,NULL
end start
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;gethostbyname.asm
.386
.model flat,stdcall
option casemap:none
include windows.inc
include kernel32.inc
include WS2_32.inc
invoke ExitProcess,NULL
end start
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;gethostbyname.asm
.386
.model flat,stdcall
option casemap:none
include windows.inc
include kernel32.inc
include WS2_32.inc
includelib kernel32.lib
includelib WS2_32.lib
includelib WS2_32.lib
.data
correy db "本功能显示本地或远程主机的所有ip地址",13,10,\
"made by correy",13,10,\
"QQ:112426112",13,10,\
"Email:leguanyuan@126.com",13,10,\
"Homepage:http://correy.webs.com",13,10,\
"请输入本地或远程的主机名:",0dh,0ah,0
err db "err",0
entry db 13,10,0
over db "按回车键结束!",0
correy db "本功能显示本地或远程主机的所有ip地址",13,10,\
"made by correy",13,10,\
"QQ:112426112",13,10,\
"Email:leguanyuan@126.com",13,10,\
"Homepage:http://correy.webs.com",13,10,\
"请输入本地或远程的主机名:",0dh,0ah,0
err db "err",0
entry db 13,10,0
over db "按回车键结束!",0
.data?
lpWSAData WSADATA <>
buffer db 256 DUP (?)
buffer2 db 256 DUP (?)
hstdin dd ?
hstdout dd ?
x dd ?
y dd ?
lpWSAData WSADATA <>
buffer db 256 DUP (?)
buffer2 db 256 DUP (?)
hstdin dd ?
hstdout dd ?
x dd ?
y dd ?
.code
start:
start:
invoke GetStdHandle,-10
mov hstdin,eax
invoke GetStdHandle,-11
mov hstdout,eax
mov hstdin,eax
invoke GetStdHandle,-11
mov hstdout,eax
invoke WSAStartup,2,addr lpWSAData
invoke WriteFile,hstdout,addr correy,sizeof correy-1,0,0
invoke RtlZeroMemory,addr buffer,sizeof buffer
invoke ReadFile,hstdin,addr buffer,sizeof buffer,addr y,0
;invoke WriteFile,hstdout,addr buffer,sizeof buffer,0,0
invoke RtlZeroMemory,addr buffer,sizeof buffer
invoke ReadFile,hstdin,addr buffer,sizeof buffer,addr y,0
;invoke WriteFile,hstdout,addr buffer,sizeof buffer,0,0
invoke lstrlen,addr buffer
sub eax,2
mov ecx,eax
lea esi,buffer
lea edi,buffer2
rep movsb
sub eax,2
mov ecx,eax
lea esi,buffer
lea edi,buffer2
rep movsb
invoke gethostbyname,addr buffer2
cmp eax,0
je wrong
cmp eax,0
je wrong
mov eax,[eax+12]
next:
cmp dword ptr [eax],0
je exit
push eax
mov eax,[eax]
invoke inet_ntoa,[eax]
mov x,eax
invoke lstrlen,eax
invoke WriteFile,hstdout,x,eax,0,0
invoke WriteFile,hstdout,addr entry,2,0,0
pop eax
add eax,4
jmp next
next:
cmp dword ptr [eax],0
je exit
push eax
mov eax,[eax]
invoke inet_ntoa,[eax]
mov x,eax
invoke lstrlen,eax
invoke WriteFile,hstdout,x,eax,0,0
invoke WriteFile,hstdout,addr entry,2,0,0
pop eax
add eax,4
jmp next
wrong:
invoke WriteFile,hstdout,addr err,sizeof err,0,0
exit:
invoke WriteFile,hstdout,addr over,sizeof over,0,0
invoke ReadFile,hstdin,addr buffer,sizeof buffer,addr y,0
invoke WSACleanup
invoke ExitProcess,NULL
end start
;made at 2010.07.08
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;gethostbyaddr.asm
.386
.model flat,stdcall
option casemap:none
include windows.inc
include kernel32.inc
include WS2_32.inc
invoke WriteFile,hstdout,addr err,sizeof err,0,0
exit:
invoke WriteFile,hstdout,addr over,sizeof over,0,0
invoke ReadFile,hstdin,addr buffer,sizeof buffer,addr y,0
invoke WSACleanup
invoke ExitProcess,NULL
end start
;made at 2010.07.08
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;gethostbyaddr.asm
.386
.model flat,stdcall
option casemap:none
include windows.inc
include kernel32.inc
include WS2_32.inc
includelib kernel32.lib
includelib WS2_32.lib
includelib WS2_32.lib
.data
correy db "本功能能显示某ip地址的主机名",13,10,\
"made by correy",13,10,\
"QQ:112426112",13,10,\
"Email:leguanyuan@126.com",13,10,\
"Homepage:http://correy.webs.com",13,10,\
"请输入本地或远程的ip地址:",0dh,0ah,0
err db "运行出错,请查看是否联网或输入了正确的ip地址。",0
entry db 13,10,0
over db "按回车键结束!",0
correy db "本功能能显示某ip地址的主机名",13,10,\
"made by correy",13,10,\
"QQ:112426112",13,10,\
"Email:leguanyuan@126.com",13,10,\
"Homepage:http://correy.webs.com",13,10,\
"请输入本地或远程的ip地址:",0dh,0ah,0
err db "运行出错,请查看是否联网或输入了正确的ip地址。",0
entry db 13,10,0
over db "按回车键结束!",0
.data?
lpWSAData WSADATA <>
buffer db 256 DUP (?)
buffer2 db 256 DUP (?)
hstdin dd ?
hstdout dd ?
x dd ?
y dd ?
lpWSAData WSADATA <>
buffer db 256 DUP (?)
buffer2 db 256 DUP (?)
hstdin dd ?
hstdout dd ?
x dd ?
y dd ?
.code
start:
start:
invoke GetStdHandle,-10
mov hstdin,eax
invoke GetStdHandle,-11
mov hstdout,eax
mov hstdin,eax
invoke GetStdHandle,-11
mov hstdout,eax
invoke WSAStartup,2,addr lpWSAData
invoke WriteFile,hstdout,addr correy,sizeof correy-1,0,0
invoke RtlZeroMemory,addr buffer,sizeof buffer
invoke ReadFile,hstdin,addr buffer,sizeof buffer,addr y,0
;invoke WriteFile,hstdout,addr buffer,sizeof buffer,0,0
invoke RtlZeroMemory,addr buffer,sizeof buffer
invoke ReadFile,hstdin,addr buffer,sizeof buffer,addr y,0
;invoke WriteFile,hstdout,addr buffer,sizeof buffer,0,0
invoke lstrlen,addr buffer
sub eax,2
mov ecx,eax
lea esi,buffer
lea edi,buffer2
rep movsb
sub eax,2
mov ecx,eax
lea esi,buffer
lea edi,buffer2
rep movsb
invoke inet_addr,addr buffer2
mov y,eax
invoke gethostbyaddr,addr y,4,AF_INET
cmp eax,0
je wrong
mov y,eax
invoke gethostbyaddr,addr y,4,AF_INET
cmp eax,0
je wrong
mov eax,[eax]
mov x,eax
invoke lstrlen,eax
invoke WriteFile,hstdout,x,eax,0,0
invoke WriteFile,hstdout,addr entry,sizeof entry-1,0,0
jmp exit
mov x,eax
invoke lstrlen,eax
invoke WriteFile,hstdout,x,eax,0,0
invoke WriteFile,hstdout,addr entry,sizeof entry-1,0,0
jmp exit
wrong:
invoke WriteFile,hstdout,addr err,sizeof err-1,0,0
invoke WriteFile,hstdout,addr entry,sizeof entry-1,0,0
exit:
invoke WriteFile,hstdout,addr over,sizeof over-1,0,0
invoke ReadFile,hstdin,addr buffer,sizeof buffer,addr y,0
invoke WSACleanup
invoke ExitProcess,NULL
end start
;made at 2010.07.08
invoke WriteFile,hstdout,addr err,sizeof err-1,0,0
invoke WriteFile,hstdout,addr entry,sizeof entry-1,0,0
exit:
invoke WriteFile,hstdout,addr over,sizeof over-1,0,0
invoke ReadFile,hstdin,addr buffer,sizeof buffer,addr y,0
invoke WSACleanup
invoke ExitProcess,NULL
end start
;made at 2010.07.08
没有评论:
发表评论