一个很难的问题,请问谁能知道呢 ( 积分: 100 )

  • 主题发起人 主题发起人 minzhongshan
  • 开始时间 开始时间
M

minzhongshan

Unregistered / Unconfirmed
GUEST, unregistred user!
现在小人正在做一个过滤IP程序,现在想过滤域名的.但我只能做到IP过滤.请问怎样做呢!我只能用下面的程序来取得数据包的信息

//从一个TSocket对象中取出IP、Port和本地port信息,并从参数ip、port、localport中传出

procedure GetIPAndPort(s: TSocket; var ip: string; var port: integer; var localport: integer);
var
name: TSockAddr;
namelen: Integer;
begin
try
namelen := sizeof(name);
getpeername(s, name, namelen); //从TSocket中取得地址信息并保存到TSockAddr对象中
ip := inet_ntoa(name.sin_addr); //取IP信息
port := ntohs(name.sin_port); //取Port信息

getsockname(s, name, namelen); //取本地的地址信息
localport := ntohs(name.sin_port);
except
SendIpcMessage('PSMFirewall', Pchar(' Error at GetIPAndPort()'#0), length(' Error at GetIPAndPort()'#0), nil, 0);
SysUtils.Beep;
end;
end;


并且下面的函数是做意思.那里有这方面的介绍.
function accept; external winsocket name 'accept';
function bind; external winsocket name 'bind';
function closesocket; external winsocket name 'closesocket';
function connect; external winsocket name 'connect';
function getpeername; external winsocket name 'getpeername';
function getsockname; external winsocket name 'getsockname';
function getsockopt; external winsocket name 'getsockopt';
function htonl; external winsocket name 'htonl';
function htons; external winsocket name 'htons';
function inet_addr; external winsocket name 'inet_addr';
function inet_ntoa; external winsocket name 'inet_ntoa';
function ioctlsocket; external winsocket name 'ioctlsocket';
function listen; external winsocket name 'listen';
function ntohl; external winsocket name 'ntohl';
function ntohs; external winsocket name 'ntohs';
function recv; external winsocket name 'recv';
function recvfrom; external winsocket name 'recvfrom';
function select; external winsocket name 'select';
function send; external winsocket name 'send';
function sendto; external winsocket name 'sendto';
function setsockopt; external winsocket name 'setsockopt';
function shutdown; external winsocket name 'shutdown';
function socket; external winsocket name 'socket';

function gethostbyaddr; external winsocket name 'gethostbyaddr';
function gethostbyname; external winsocket name 'gethostbyname';
function getprotobyname; external winsocket name 'getprotobyname';
function getprotobynumber; external winsocket name 'getprotobynumber';
function getservbyname; external winsocket name 'getservbyname';
function getservbyport; external winsocket name 'getservbyport';
function gethostname; external winsocket name 'gethostname';

function WSAAsyncSelect; external winsocket name 'WSAAsyncSelect';
function WSARecvEx; external winsocket name 'WSARecvEx';
function WSAAsyncGetHostByAddr; external winsocket name 'WSAAsyncGetHostByAddr';
function WSAAsyncGetHostByName; external winsocket name 'WSAAsyncGetHostByName';
function WSAAsyncGetProtoByNumber; external winsocket name 'WSAAsyncGetProtoByNumber';
function WSAAsyncGetProtoByName; external winsocket name 'WSAAsyncGetProtoByName';
function WSAAsyncGetServByPort; external winsocket name 'WSAAsyncGetServByPort';
function WSAAsyncGetServByName; external winsocket name 'WSAAsyncGetServByName';
function WSACancelAsyncRequest; external winsocket name 'WSACancelAsyncRequest';
function WSASetBlockingHook; external winsocket name 'WSASetBlockingHook';
function WSAUnhookBlockingHook; external winsocket name 'WSAUnhookBlockingHook';
function WSAGetLastError; external winsocket name 'WSAGetLastError';
procedure WSASetLastError; external winsocket name 'WSASetLastError';
function WSACancelBlockingCall; external winsocket name 'WSACancelBlockingCall';
function WSAIsBlocking; external winsocket name 'WSAIsBlocking';
function WSAStartup; external winsocket name 'WSAStartup';
function WSACleanup; external winsocket name 'WSACleanup';
function __WSAFDIsSet; external winsocket name '__WSAFDIsSet';

function TransmitFile; external winsocket name 'TransmitFile';
function AcceptEx; external winsocket name 'AcceptEx';
procedure GetAcceptExSockaddrs; external winsocket name 'GetAcceptExSockaddrs';
 
现在小人正在做一个过滤IP程序,现在想过滤域名的.但我只能做到IP过滤.请问怎样做呢!我只能用下面的程序来取得数据包的信息

//从一个TSocket对象中取出IP、Port和本地port信息,并从参数ip、port、localport中传出

procedure GetIPAndPort(s: TSocket; var ip: string; var port: integer; var localport: integer);
var
name: TSockAddr;
namelen: Integer;
begin
try
namelen := sizeof(name);
getpeername(s, name, namelen); //从TSocket中取得地址信息并保存到TSockAddr对象中
ip := inet_ntoa(name.sin_addr); //取IP信息
port := ntohs(name.sin_port); //取Port信息

getsockname(s, name, namelen); //取本地的地址信息
localport := ntohs(name.sin_port);
except
SendIpcMessage('PSMFirewall', Pchar(' Error at GetIPAndPort()'#0), length(' Error at GetIPAndPort()'#0), nil, 0);
SysUtils.Beep;
end;
end;


并且下面的函数是做意思.那里有这方面的介绍.
function accept; external winsocket name 'accept';
function bind; external winsocket name 'bind';
function closesocket; external winsocket name 'closesocket';
function connect; external winsocket name 'connect';
function getpeername; external winsocket name 'getpeername';
function getsockname; external winsocket name 'getsockname';
function getsockopt; external winsocket name 'getsockopt';
function htonl; external winsocket name 'htonl';
function htons; external winsocket name 'htons';
function inet_addr; external winsocket name 'inet_addr';
function inet_ntoa; external winsocket name 'inet_ntoa';
function ioctlsocket; external winsocket name 'ioctlsocket';
function listen; external winsocket name 'listen';
function ntohl; external winsocket name 'ntohl';
function ntohs; external winsocket name 'ntohs';
function recv; external winsocket name 'recv';
function recvfrom; external winsocket name 'recvfrom';
function select; external winsocket name 'select';
function send; external winsocket name 'send';
function sendto; external winsocket name 'sendto';
function setsockopt; external winsocket name 'setsockopt';
function shutdown; external winsocket name 'shutdown';
function socket; external winsocket name 'socket';

function gethostbyaddr; external winsocket name 'gethostbyaddr';
function gethostbyname; external winsocket name 'gethostbyname';
function getprotobyname; external winsocket name 'getprotobyname';
function getprotobynumber; external winsocket name 'getprotobynumber';
function getservbyname; external winsocket name 'getservbyname';
function getservbyport; external winsocket name 'getservbyport';
function gethostname; external winsocket name 'gethostname';

function WSAAsyncSelect; external winsocket name 'WSAAsyncSelect';
function WSARecvEx; external winsocket name 'WSARecvEx';
function WSAAsyncGetHostByAddr; external winsocket name 'WSAAsyncGetHostByAddr';
function WSAAsyncGetHostByName; external winsocket name 'WSAAsyncGetHostByName';
function WSAAsyncGetProtoByNumber; external winsocket name 'WSAAsyncGetProtoByNumber';
function WSAAsyncGetProtoByName; external winsocket name 'WSAAsyncGetProtoByName';
function WSAAsyncGetServByPort; external winsocket name 'WSAAsyncGetServByPort';
function WSAAsyncGetServByName; external winsocket name 'WSAAsyncGetServByName';
function WSACancelAsyncRequest; external winsocket name 'WSACancelAsyncRequest';
function WSASetBlockingHook; external winsocket name 'WSASetBlockingHook';
function WSAUnhookBlockingHook; external winsocket name 'WSAUnhookBlockingHook';
function WSAGetLastError; external winsocket name 'WSAGetLastError';
procedure WSASetLastError; external winsocket name 'WSASetLastError';
function WSACancelBlockingCall; external winsocket name 'WSACancelBlockingCall';
function WSAIsBlocking; external winsocket name 'WSAIsBlocking';
function WSAStartup; external winsocket name 'WSAStartup';
function WSACleanup; external winsocket name 'WSACleanup';
function __WSAFDIsSet; external winsocket name '__WSAFDIsSet';

function TransmitFile; external winsocket name 'TransmitFile';
function AcceptEx; external winsocket name 'AcceptEx';
procedure GetAcceptExSockaddrs; external winsocket name 'GetAcceptExSockaddrs';
 
怎么没有懂的
 
帮顶

--------签名档---------------------------

惊爆开源站

http://www.source520.com

80G源码电子书免费免注册下载,大量精辟技术文档库随时更新
 
以下是从我的一个程序里取出来的,你可以看一下
var
HostInfo : PHostEnt; //这个是保存主机信息的一个记录

//根据远程主机的IP取得它的信息
HostInfo := GetHostByAddr(@pAddr[0], 4, PF_INET);
if HostInfo = nil then
begin
ShowMessage(IntToStr(WSAGetLastError));
exit;
end;//if
pName := HostInfo^.h_name; //远程主机名字

//根据远程主机名字取得它的信息
HostInfo := GetHostByName(PChar(edtDomainName.Text));//输入主机名,或网址
if HostInfo = nil then
begin
ShowMessage('未找到');
exit;
end;//if
pAddr := HostInfo^.h_addr_list^;
strIP := Format('%d.%d.%d.%d', [byte(pAddr[0]), byte(pAddr[1]), byte(pAddr[2]), byte (pAddr[3])]);
ShowMessage(strIP);

你可以用先确定你要屏蔽的IP,根据第一个从IP取得信息的函数得到域名,然后再屏蔽.
不知道这个能不能满足你的要求.
另外下面的那些函数自己查MSDN就行,虽然不一定每个都有,绝大部分肯定是有的.
 
163正向查询得到:
163.com:220.181.29.154
反向查询得到:
220.181.29.154:未找到

大富翁正向查询得到:
delphibbs.com:222.39.0.130
大富翁反向查询得到:
222.39.0.130:未找到

雅虎正向查询得到:
www.Yahoo.com:68.142.226.35
雅虎反向查询得到:
68.142.226.35:p4.www.re2.yahoo.com

雅虎蜘蛛反向查询得到:
68.142.251.178:lj2568.inktomisearch.com
雅虎蜘蛛正向查询得到:
lj2568.inktomisearch.com:68.142.251.178

我想你能写底层Socket的应用,也应该明白我上面列举的意义了。
 
首先,谢谢楼上指出的问题。
鉴于我的程序和楼主需要的用途有一定差异,所以我说了“不知道能不能满足你的要求”。
其次,关于这个反查询,由于一部分IP可能是网关的地址,而并不保证是主机地址。另外,也可能会是出于安全方面的原因,就像我用IP取我母校的域名,前3次能成功,后面就报“找不到”了。还有的可能就是大网站在分布式方面的问题了(不懂.........)。
再次,根据域名访问之所以能直接找到主机,我个人认识如下,自己的理解,不一定对...
1.如果是静态域名或没有网关,在没有特殊限制的情况下应该能直接访问。
2.内部主机借由某些如“花生壳”这样的服务器提供的服务,你可以申请一个动态域名。我想服务器内部也就是将它所拥有的静态域名指向你在网关上的镜像地址(如果你处在局域网中)。当别人使用你这个域名访问时,DNS服务器当然会有上述提到的那个静态域名的记录,然后会把域名解析成主机地址,注意它也知道发往具体的那个端口,然后,访问者会向这个地址发送相关的报文,在目的主机的网关处,收到这个数据报或流时,会根据接
收到数据的端口的端口号,查到具体哪台主机要对这些报文负责,最终访问者将访问到那个域名的主机。
最后,由于我的刚涉足网络方面的编程,所以我只能对楼主的这个程序提个建议,列个常用的域名和IP的对应关系表,在登陆了某个以后再也不想登陆的网址后-〉域名toIP-〉记录下来,以后查表吧.........
 
后退
顶部