ios 怎么c 通过域名获取ip来获取ip

> 只用C语言,怎么通过域名得到IP地址
只用C语言,怎么通过域名得到IP地址
tengzi & &
发布时间: & &
浏览:10 & &
回复:3 & &
悬赏:0.0希赛币
只用C语言,如何通过域名得到IP地址请问各位高手,在一个单片机程序下,如何只用C语言,如何通过域名得到IP地址?现在没有DNS服务器。
gethostbyname()函数
tens088 & &
12:19:36 & &
& & (0)(0)引用gethostbyname
gethostbyname
information
corresponding
gethostbyname
Parameters
null-terminated
gethostbyname
successful
parameter.
application
components.
Furthermore,
application
information
gethostbyname
gethostbyaddr,
structure.
gethostbyname
successful
gethostname.
gethostbyname
Otherwise,
WSAGetLastError.
WSANOTINITIALISED
successful
WSAStartup
WSAENETDOWN
WSAHOST_NOT_FOUND
Authoritative
WSATRY_AGAIN
Non-Authoritative
WSANO_RECOVERY
Nonrecoverable
WSANO_DATA
WSAEINPROGRESS
processing
WSACancelBlockingCall.
winsock2.h.
ws2_32.lib.
tenny52 & &
12:19:36 & &
& & (0)(0)引用#include &winsock2.h&#include &iostream&#pragma comment(lib,&ws2_32.lib&)int main(){ WSADATA WSAStartup(MAKEWORD(2,2),&wsadata); hostent *phost=gethostbyname(&&); in_ for(int i=0;;i++) {
char *p=phost-&h_addr_list[i];
if(p==NULL)
memcpy(&addr.S_un.S_addr,p,phost-&h_length);tens088 & &
12:19:36 & &
& & (0)(0)引用
本问题标题:
本问题地址:
温馨提示:本问答中心的任何言论仅代表发言者个人的观点,与希赛网立场无关。请对您的言论负责,遵守中华人民共和国有关法律、法规。如果您的言论违反希赛网问答中心的规则,将会被删除。
暂无合适的专家
&&&&&&&&&&&&&&&
希赛网 版权所有 & &&10:36 提问
ios如何获取局域网内所有ip
使用代码获取连在同一个局域网内的其它设备的ip地址,类似于搜索到周边的电脑的ip地址
按赞数排序
An iOS Local Area Network / wifi Scanner
(NSString *)localIPAddress
NSString *localIP =
struct ifaddrs *
if (getifaddrs(&addrs)==0) {
const struc......答案就在这里:----------------------你好,人类,我是来自CSDN星球的问答机器人小C,以上是依据我对问题的理解给出的答案,如果解决了你的问题,望采纳。帐号:密码:下次自动登录{url:/nForum/slist.json?uid=guest&root=list-section}{url:/nForum/nlist.json?uid=guest&root=list-section}
贴数:2&分页:水母青蛙发信人: fancolumn (水母青蛙), 信区: MobileDev
标&&题: xcode/ios 下如何将域名转换成IP地址?
发信站: 水木社区 (Fri Aug 17 22:43:31 2012), 站内 && 谢谢。
-- && ※ 来源:·水木社区 ·[FROM: 113.31.35.*]
xk发信人: xkong (xk), 信区: MobileDev
标&&题: Re: xcode/ios 下如何将域名转换成IP地址?
发信站: 水木社区 (Fri Aug 17 23:39:07 2012), 站内 && 用系统调用就可以了 && #include &netdb.h&
#include &arpa/inet.h& && // Get host entry info for given host
struct hostent *remoteHostEnt = gethostbyname(“”); && // Get address info from host entry
struct in_addr *remoteInAddr = (struct in_addr *) remoteHostEnt-
&h_addr_list[0]; && // Convert numeric addr to ASCII string
char *sRemoteInAddr = inet_ntoa(*remoteInAddr); &&&& 【 在 fancolumn (水母青蛙) 的大作中提到: 】
-- && ※ 来源:·水木社区 ·[FROM: 114.246.67.*]
文章数:2&分页:iOS获取手机ip地址代码
来源:it-home
本文实例为大家分享了iOS获取手机ip地址的具体代码,供大家参考,具体内容如下
#import &ifaddrs.h&#import &arpa/inet.h&// Get IP Address- (NSString *)getIPAddress {
NSString *address = @"error";
struct ifaddrs *interfaces = NULL;
struct ifaddrs *temp_addr = NULL;
int success = 0;
// retrieve the current interfaces - returns 0 on success
success = getifaddrs(&interfaces);
if (success == 0) {
// Loop through linked list of interfaces
temp_addr =
while(temp_addr != NULL) {
if(temp_addr-&ifa_addr-&sa_family == AF_INET) {
// Check if interface is en0 which is the wifi connection on the iPhone
if([[NSString stringWithUTF8String:temp_addr-&ifa_name] isEqualToString:@"en0"]) {
// Get NSString from C String
address = [NSString stringWithUTF8String:inet_ntoa(((struct sockaddr_in *)temp_addr-&ifa_addr)-&sin_addr)];
temp_addr = temp_addr-&ifa_
// Free memory
freeifaddrs(interfaces);}复制代码
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持之家。
免责声明:本站部分内容、图片、文字、视频等来自于互联网,仅供大家学习与交流。相关内容如涉嫌侵犯您的知识产权或其他合法权益,请向本站发送有效通知,我们会及时处理。反馈邮箱&&&&。
学生服务号
在线咨询,奖学金返现,名师点评,等你来互动&&&&iOS获取用户设备当前的IP地址
iOS获取用户设备当前的IP地址
iOS获取用户设备当前的IP地址
若举报审核通过,可奖励20下载分
被举报人:
举报的资源分:
请选择类型
资源无法下载
资源无法使用
标题与实际内容不符
含有危害国家安全内容
含有反动色情等内容
含广告内容
版权问题,侵犯个人或公司的版权
*详细原因:
VIP下载&&免积分60元/年(1200次)
您可能还需要
移动开发下载排行

我要回帖

更多关于 获取域名ip 的文章

 

随机推荐