端口扫描的问题

  • 主题发起人 主题发起人 import
  • 开始时间 开始时间
I

import

Unregistered / Unconfirmed
GUEST, unregistred user!
在写端口扫描时,如果与某主机特定端口无法通信, 就此主机而言,我想应该有以下两种情况:
1。此地址上无任何主机存在
2。有主机但被扫描的特定端口不存在(也可能是被firewall过滤了)
请问如何编程区分这两种情况
最好详细一点喔(我很笨的)
如果在此地址上无主机存在,则发出的数据包得不到回应,应用程序会等待超时才
认为连接失败(被firewall过滤时情况一样),若有主机但被扫描的特定端口不存在时,
该主机会发出目的端口不存在的应答
至于如何编程实现,应该可以由错误码来判断,在OnError事情中判定ErrorCode是多
小,再分别处理,ErrorCode的详情参见Help
这么高深的问题才50分,少了
端口扫描不是这么简单,否则大家都做
首先你扫描人家的端口会留下自己的痕迹,系统有日志可以察看
因此我们做端口扫描的的时候绝对不会直接连接别人,而是通过地层的接口编程
例如在TCP三次握手的第三次放弃,对方就不会有日志,这称为sys扫描
给对方端口发断开连接的请求称为fin扫描.
通过这两种扫描方式都可以得知对方的端口是否开,而且不会留下痕迹.
总之端口扫描里面有很多学问,不是这里可以说清除的
怎么做呀,如你所说的话好象要直接调用socket api?
我现在首先关心的是我提出的问题,如何编程区分这两种情况:
1。此地址上无任何主机存在
2。有主机但被扫描的特定端口不存在(也可能是被firewall过滤了)
 
还有,为什么我把clientsocket的onread里的errorcode设为0了,
还是常常会出现delphi自己的错误消息提示,象10061,10057什么的,
这好象是另外一种error code,如能把它屏蔽我想就不会出现提示了.
是吗?如果是,该怎么做呢。
最后:如果能给我一个多线程的端口扫描源码,我再给100分(真的很穷啊)
我找到了help里的有关说明(是在索引中 Error TCP Event 里找到的)
 
WinSock Error Codes
The following error codes apply to the WinSock ActiveX Controls.
Error Code Error Message
10004 The operation is canceled.
10013 The requested address is a broadcast address, but flag is not set.
10014 Invalid argument.
10022 Socket not bound, invalid address or listen is not invoked prior to accept.
10024 No more file descriptors are available, accept queue is empty.
10035 Socket is non-blocking and the specified operation will block.
10036 A blocking Winsock operation is in progress.
10037 The operation is completed. No blocking operation is in progress.
10038 The descriptor is not a socket.
10039 Destination address is required.
10040 The datagram is too large to fit into the buffer and is truncated.
10041 The specified port is the wrong type for this socket.
10042 Option unknown, or unsupported.
10043 The specified port is not supported.
10044 Socket type not supported in this address family.
10045 Socket is not a type that supports connection oriented service.
10047 Address Family is not supported.
10048 Address in use.
10049 Address is not available from the local machine.
10050 Network subsystem failed.
10051 The network cannot be reached from this host at this time.
10052 Connection has timed out when SO_KEEPALIVE is set.
10053 Connection is aborted due to timeout or other failure.
10054 The connection is reset by remote side.
10055 No buffer space is available.
10056 Socket is already connected.
10057 Socket is not connected.
10058 Socket has been shut down.
10060 The attempt to connect timed out.
10061 Connection is forcefully rejected.
10201 Socket already created for this object.
10202 Socket has not been created for this object.
11001 Authoritative answer: Host not found.
11002 Non-Authoritative answer: Host not found.
11003 Non-recoverable errors.
11004 Valid name, no data record of requested type.
我想只要对它进行有关操作就能完全屏蔽winsocket错误消息(至少
能屏蔽很多onerror里的errorcode参数无法屏蔽的消息)
我终于找到原因所在了
在打开Socket时也要捕获异常
try
ClientSocket.Open;
except
MessageBox(MainForm.Handle,'Error connecting to this address','Connect',MB_ICONEXCLAMATION);
end;
在OnError中最后要将ErrorCode置为0
if ErrorEvent=eeConnect then
begin
Socket.Close;
MessageBox(MainForm.Handle,'Error connecting to this address','Connect',MB_ICONEXCLAMATION);
end
else if ErrorEvent=eeSend then
Socket.Close;
ErrorCode:=0;
你可能无做第一步
而这样也可以区分你所说的两种情况
1。第二步OnError就是此地址上无任何主机存在,到超时就触发OnError事件
2。第一步捕捉到异常就是有主机但被扫描的特定端口不存在
 
 
 
后退
顶部