=======================================================================
版权没有,转载自由!!!不过希望你能贴出改进的版本!
搞得都是自己问自己答了,呵呵,100分啊,又不能给自己,所以,谁把多线程的
写出来,谁就可以得分,最好是给一些线程的相关资料。比如说用createthread
怎么来实现,而用tthread 类怎么来实现!!!!!!!!!!!!!!!!!
=======================================================================
源程序如下:
program Project1;
{$APPTYPE CONSOLE}
uses winsock,sysutils,windows;
const
startport=1;
stopport=30;
var
s:tsocket;
i,j,error:integer;
server:tsockaddrin;
wsa:twsadata;
begin
writeln('===============================================================================');
writeln('== Very Slow Port Scanner ==');
writeln('== Edit by whaoye@21cn.com ==');
writeln('===============================================================================');
writeln(' == ==');
writeln(' == ==');
writeln(' =====================================================================');
writeln(' == ==');
wsastartup(makeword(1,1),wsa);
server.sin_family:=AF_INET;
server.sin_addr.S_addr:=inet_addr('127.0.0.1');
for i:=startport to stopport do
begin
s:=socket(AF_INET, SOCK_STREAM, 0);
server.sin_port:=htons(i);
error:=connect(s,server,sizeof(server));
if error=0 then
begin
write(' == Scan port: '+inttostr(i));
for j:=0 to 5-length(inttostr(i)) do
write(' ');
writeln(' [ok] ==');
closesocket(s);
end;
end;
writeln(' == ==');
writeln(' =====================================================================');
writeln(' == ==');
writeln(' == ==');
writeln('===============================================================================');
writeln('== Thank you for your test! Good luck! ==');
writeln('== Edit by whaoye@21cn.com ==');
writeln('===============================================================================');
wsacleanup();
end.