局域网中如何得到其它机器的IP?
比如说我以经知道其它机器的机器名。
谢谢!
问题点数:50、回复次数:5Top
1 楼ciml(镜子)回复于 2002-02-28 17:21:38 得分 0
用socket函数,自己查一下msdnTop
2 楼webtt(tt)回复于 2002-02-28 17:23:43 得分 5
gethostbyaddr,用此函数之前要初始化socketTop
3 楼xiaowei27(小阿伟)回复于 2002-02-28 17:32:08 得分 0
大哥啊,能不能举个例子?我看不懂也。。Top
4 楼invalid(空心菜(Python是个好东东,大家多用用!))回复于 2002-02-28 17:43:39 得分 40
用struct hostent FAR * gethostbyname ( const char FAR * name );
struct hostent {
char FAR * h_name;
char FAR * FAR * h_aliases;
short h_addrtype;
short h_length;
char FAR * FAR * h_addr_list;
};
h_name
Official name of the host (PC).If using the DNS or similar resolution system, it is the Fully Qualified Domain Name (FQDN) that caused the server to return a reply. If using a local "hosts" file, it is the first entry after the IP address.
h_aliases
A NULL-terminated array of alternate names.
h_addrtype
The type of address being returned.
h_length
The length, in bytes, of each address.
h_addr_list
A NULL-terminated list of addresses for the host. Addresses are returned in network byte order.The macro h_addr is defined to be h_addr_list[0] for compatibility with older software.
先用gethostbyname,然后h_addr_list[0]就是ip地址。Top
5 楼Jujus(某人)回复于 2002-02-28 17:49:34 得分 5
先用WNetEnumResource枚举局域网的所有机器,这是得到的是机器hostname,再用gethostbyname取到他的IP就行了,呵呵,我在Delphi下写过一个,不过搞不清楚放在哪里了:PTop




