Chinaunix首页 | 论坛 | 博客
  • 博客访问: 307442
  • 博文数量: 214
  • 博客积分: 4258
  • 博客等级: 上校
  • 技术积分: 2021
  • 用 户 组: 普通用户
  • 注册时间: 2010-12-02 09:16
个人简介

http://blog.csdn.net/ly21st http://ly21st.blog.chinaunix.net

文章分类

全部博文(214)

文章存档

2018年(16)

2015年(1)

2014年(2)

2012年(22)

2011年(173)

分类: LINUX

2011-09-21 10:34:04

#include
#include
#include
#include
#include
#include
#include     //added by liyuan
#include     //added by liyuan
#include      //added by liyuan
int main (int argc, char *argv[])
{
 struct hostent *h;
 /* 检测命令行中的参数是否存在 */
 if (argc != 2) {
   /* 如果没有参数,给出使用方法 */
   printf ("usage: getip address\n");
   /* 然后退出 */
   exit(1);
 }
 
 /* 取得主机信息 */
 if ((h=gethostbyname(argv[1])) == NULL){
  /* 如果gethostbyname失败,则给出错误信息 */
  herror("gethostbyname");
  /* 然后退出 */
  exit(1);
 }
 /* 列印程序取得的信息 */
 printf("Host name: %s\n", h->h_name);
 printf("IP Address: %s\n",inet_ntoa (*((struct in_addr *)h->h_addr)));
 /* 返回 */
 return 0;
}
阅读(179) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~