如何得到客户端的IP或机器名?(200分)

Z

zc

Unregistered / Unconfirmed
GUEST, unregistred user!
在三层结构中,中间层如何知道连接的客户端的IP或机器名?
用作安全验证,所以不能由客户端传
其他可有类似或更好的方案?
 
参见WSAAccept的HELP.里面的参数addr是输出的,其结果就是CLIENT
的地址描述.
 
我认为可以使用客户端传送. 至于安全问题, 你可以使用PGP加密算法
(保管每人可以解开!). 在http://www.pgpi.com中有PGPSDK和免费的
DLL(SPGP.DLL).
 
I think it is dangerous to distinguish a client only by IP or machine name. you should use security socket layer(good manner) or mac address(also not very safe).
 
根据江湖上故老相传,据说服务器端是绝对访问不了客户端的,这好象是Midas的设计思想之一,所以只能由客户端传了。至于安全性,我觉得Jimchael Tsee说的有道理,再说你传数据传得太多了,客户端登录、请求、返回数据,多如牛毛,要是全都担心安全,干脆别干了,敏感一点的数据自己加密一下就行了。
 
许多网络系统本身就提供加密的
 
以下是从DELPHI一个站点的得到的答案
看是否合适

Detect my own IP Address ?

From: Andreas Hoerstemeier <andy@scp.de>

> How can I detect my own IP address in delphi 1?

---------------------------------------------------------------------

function my_ip_address:longint;
const
bufsize=255;
var
buf: pointer;
RemoteHost : PHostEnt; (* No, don't free it! *)
begin
buf:=NIL;
try
getmem(buf,bufsize);
winsock.gethostname(buf,bufsize); (* this one maybe without domain *)
RemoteHost:=Winsock.GetHostByName(buf);
if RemoteHost=NIL then
my_ip_address:=winsock.htonl($07000001) (* 127.0.0.1 *)
else
my_ip_address:=longint(pointer(RemoteHost^.h_addr_list^)^);
finally
if buf<>NIL then freemem(buf,bufsize);
end;
result:=winsock.ntohl(result);
end;

----------------------------------------------------------------------

This give the (first) network address of the local computer, and if not connected the 127.0.0.1 as the standard address for the local computer.
You only need a winsock.dcu/winsock.pas as this one isn't included with D1; I have one together with my tcpip component pack (where I snipped out the above routine).


 
我觉得还是要采用客户端传的办法,如果说考虑安全问题的话,那客户端
还可以通过发送IP包进行模拟,所以不如通过客户端传送的方法.
 
多人接受答案了。
 
顶部