L
linfe
Unregistered / Unconfirmed
GUEST, unregistred user!
我写了个扫描器。不过最近中病毒,格掉了整个硬盘。
代码有如:
var
addr:TSockAddr;
m_sock:TSOCKET;
flag:boolean;
procedure TForm1.Port(src,dest:integer;ip:string);
var
i:integer;
begin
memo1.Lines.Add('端口号 状态');
memo1.Lines.Add('------------------------------');
if dest=0 then
begin
addr.sin_family:=AF_INET;
addr.sin_port:=htons(word(src));
addr.sin_addr.S_addr:=inet_addr(pchar(ip));
m_sock:=socket(AF_INET,SOCK_STREAM,0);
if connect(m_sock,addr,sizeof(addr))=0 then
begin
memo1.Lines.Add(inttostr(src)+' 开放的');
end
else
begin
memo1.Lines.Add(inttostr(src)+' 关闭的');
end;
closesocket(m_sock);
end
else
begin
if dest<=src then
begin
showmessage('端口值设置不合理,请看说明!');
end
else
begin
for i:=src to dest do
begin
if flag then
begin
addr.sin_family:=AF_INET;
addr.sin_port:=htons(word(i));
addr.sin_addr.S_addr:=inet_addr(pchar(ip));
m_sock:=socket(AF_INET,SOCK_STREAM,0);
if connect(m_sock,addr,sizeof(addr))=INVALID_SOCKET then
begin
memo1.Lines.Add(inttostr(i)+' 开放的');
end
else
begin
memo1.Lines.Add(inttostr(i)+' 关闭的');
end;
closesocket(m_sock);
m_sock:=0;
application.ProcessMessages;
end
else
break;
end;
end;
end;
memo1.Lines.Add('------------------------------');
memo1.Lines.Add('注:显示关闭的端口可能有两种情况');
memo1.Lines.Add('1:端口真的关闭了!');
memo1.Lines.Add('2:可能网络不通,导致数据连接失败,返回端口关闭的信息');
memo1.Lines.Add('---------'+formatdatetime('yyyy/mm/dd hh:mm:ss',now()));
end;
procedure TForm1.FormCreate(Sender: TObject);
var
WD:WSADATA;
begin
WSAStartup($202,WD);
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
WSACleanup();
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if (edit1.Text='')or(edit2.Text='') then
begin
showmessage('请将信息填写完整!');
exit;
end;
flag:=true;
if RadioButton1.Checked then
begin
port(strtoint(edit2.Text),0,edit1.Text);
end;
if (RadioButton2.Checked)and (edit3.Text<>'') then
begin
port(strtoint(edit2.Text),strtoint(edit3.Text),edit1.Text);
end
else
showmessage('请将信息填写完整!');
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
flag:=false;
closesocket(m_sock);
end;
procedure TForm1.Button2Click(Sender: TObject);
var
filestr:string;
begin
filestr:=changefileext(application.ExeName,'.log');
memo1.Lines.SaveToFile(filestr);
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
memo1.Lines.Clear;
end;
代码查不多,但感觉速度很慢,
差不多一秒钟扫描一个端口。
是不是要用到多线程,还是用其他办法?
另外问一下,stdcall是什么意思?
请各位赐教!
给个思路,最好有源代码。
分不够可以加~~~
代码有如:
var
addr:TSockAddr;
m_sock:TSOCKET;
flag:boolean;
procedure TForm1.Port(src,dest:integer;ip:string);
var
i:integer;
begin
memo1.Lines.Add('端口号 状态');
memo1.Lines.Add('------------------------------');
if dest=0 then
begin
addr.sin_family:=AF_INET;
addr.sin_port:=htons(word(src));
addr.sin_addr.S_addr:=inet_addr(pchar(ip));
m_sock:=socket(AF_INET,SOCK_STREAM,0);
if connect(m_sock,addr,sizeof(addr))=0 then
begin
memo1.Lines.Add(inttostr(src)+' 开放的');
end
else
begin
memo1.Lines.Add(inttostr(src)+' 关闭的');
end;
closesocket(m_sock);
end
else
begin
if dest<=src then
begin
showmessage('端口值设置不合理,请看说明!');
end
else
begin
for i:=src to dest do
begin
if flag then
begin
addr.sin_family:=AF_INET;
addr.sin_port:=htons(word(i));
addr.sin_addr.S_addr:=inet_addr(pchar(ip));
m_sock:=socket(AF_INET,SOCK_STREAM,0);
if connect(m_sock,addr,sizeof(addr))=INVALID_SOCKET then
begin
memo1.Lines.Add(inttostr(i)+' 开放的');
end
else
begin
memo1.Lines.Add(inttostr(i)+' 关闭的');
end;
closesocket(m_sock);
m_sock:=0;
application.ProcessMessages;
end
else
break;
end;
end;
end;
memo1.Lines.Add('------------------------------');
memo1.Lines.Add('注:显示关闭的端口可能有两种情况');
memo1.Lines.Add('1:端口真的关闭了!');
memo1.Lines.Add('2:可能网络不通,导致数据连接失败,返回端口关闭的信息');
memo1.Lines.Add('---------'+formatdatetime('yyyy/mm/dd hh:mm:ss',now()));
end;
procedure TForm1.FormCreate(Sender: TObject);
var
WD:WSADATA;
begin
WSAStartup($202,WD);
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
WSACleanup();
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if (edit1.Text='')or(edit2.Text='') then
begin
showmessage('请将信息填写完整!');
exit;
end;
flag:=true;
if RadioButton1.Checked then
begin
port(strtoint(edit2.Text),0,edit1.Text);
end;
if (RadioButton2.Checked)and (edit3.Text<>'') then
begin
port(strtoint(edit2.Text),strtoint(edit3.Text),edit1.Text);
end
else
showmessage('请将信息填写完整!');
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
flag:=false;
closesocket(m_sock);
end;
procedure TForm1.Button2Click(Sender: TObject);
var
filestr:string;
begin
filestr:=changefileext(application.ExeName,'.log');
memo1.Lines.SaveToFile(filestr);
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
memo1.Lines.Clear;
end;
代码查不多,但感觉速度很慢,
差不多一秒钟扫描一个端口。
是不是要用到多线程,还是用其他办法?
另外问一下,stdcall是什么意思?
请各位赐教!
给个思路,最好有源代码。
分不够可以加~~~