在局域网中,如何通过IP地址获得对方电脑的名称? ping -a ip 就可以编程的话,你可以参考老贴子 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 Uses WinSock;procedure GetHostName;VAR S:String;wVersionRequested:WORD;wsaData:tWSADATA;HostEnt:THostEnt;P:PHostEnt;HostAddr:Integer;begin wVersionRequested:= MAKEWORD( 2, 2 ); WSAStartup(wVersionRequested,WSADATA); S:=YourIPAddress;//这边填入你的IP HostAddr:=0; HostAddr:=inet_addr(PChar(S));P:=gethostbyaddr(PChar(@HostAddr),4,PF_INET);if p<>nil then ShowMessage(P^.h_name); WSACleanup;end; 右击打开网上邻居的属性,点击TIP 协议,点击属性,可以在IP地址里输入对方的机号,添加即可,并在网关,DNS里面输入相应的号 远程控制篇:通过机器名得到IP地址 通过IP地址得到机器名 远程控制篇:通过机器名得到IP地址function procedure TForm1.nametoip(name:string):string;var WSAData: TWSAData; HostEnt: PHostEnt;begin result:=''; WSAStartup(2, WSAData); HostEnt := gethostbyname(PChar(name)); if HostEnt <> nil then begin with HostEnt^ do result:= Format('%d.%d.%d.%d', [Byte(h_addr^[0]), Byte(h_addr^[1]), Byte(h_addr^[2]), Byte(h_addr^[3])]); end; WSACleanup;end;通过IP地址得到机器名function iptoname(ip:string):string;var WSAData:TWSAData; p:PHostEnt; InetAddr:dword;begin WSAStartup(2, WSAData); InetAddr:= inet_addr(PChar(IP));try p:=GetHostByAddr(@InetAddr, Length(IP), PF_Inet); result:=p^.h_name; except result:=''; end;end; delphi 7如何调用https://的web service Delphi程序模块化设计 如何获得指定进程的句柄? 在delphi写的程序中如何使用收发并储存email的功能(就相当与outlook的功能) 求教 ,NVL的问题 做线程的高手请进! 异常处理的问题,高手进来看..... 经典win32环境下的com组件 TrewView上的TreeNode怎么响应事件呀?TreeNode是动态添加的。 一个mdi应用程序中子窗体关闭时候的错误 谁有多表头控件!!!急 谁能告诉我DATETIMEPICKER控件是不是有BUG,它的最大时间与最小时间是不是有问题?
procedure GetHostName;
VAR
S:String;
wVersionRequested:WORD;
wsaData:tWSADATA;
HostEnt:THostEnt;
P:PHostEnt;
HostAddr:Integer;
begin
wVersionRequested:= MAKEWORD( 2, 2 );
WSAStartup(wVersionRequested,WSADATA);
S:=YourIPAddress;//这边填入你的IP
HostAddr:=0;
HostAddr:=inet_addr(PChar(S));
P:=gethostbyaddr(PChar(@HostAddr),4,PF_INET);
if p<>nil then ShowMessage(P^.h_name);
WSACleanup;
end;
即可,并在网关,DNS里面输入相应的号
远程控制篇:通过机器名得到IP地址function procedure TForm1.nametoip(name:string):string;
var
WSAData: TWSAData;
HostEnt: PHostEnt;
begin
result:='';
WSAStartup(2, WSAData);
HostEnt := gethostbyname(PChar(name));
if HostEnt <> nil then
begin
with HostEnt^ do
result:= Format('%d.%d.%d.%d', [Byte(h_addr^[0]), Byte(h_addr^[1]), Byte(h_addr^[2]), Byte(h_addr^[3])]);
end;
WSACleanup;
end;通过IP地址得到机器名function iptoname(ip:string):string;
var
WSAData:TWSAData;
p:PHostEnt;
InetAddr:dword;
begin
WSAStartup(2, WSAData);
InetAddr:= inet_addr(PChar(IP));
try
p:=GetHostByAddr(@InetAddr, Length(IP), PF_Inet);
result:=p^.h_name;
except
result:='';
end;
end;