如何伪装某个IP地址,向别人发送UDP数据包呢 有大侠做过吗?指点指点,研究这个只是个人兴趣,没有其他恶意! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这个是别人的代码:if((sock_primordial=socket(AF_INET,SOCK_RAW,IPPROTO_RAW))==-1) 53 { 54 cout<<"create sock error!"<<endl; 55 } 56 57 int on=1; 58 if(setsockopt(sock_primordial, IPPROTO_IP,IP_HDRINCL,&on,sizeof(on))== -1) 59 { 60 cout<<"set sock opt error!"<<endl; 61 } 62 63 bzero(buffer,IP_TOTAL_SIZE); 64 65 ip=(struct ip *)buffer; 66 ip->ip_v=IPVERSION; 67 ip->ip_hl=5; 68 ip->ip_tos=0; 69 ip->ip_len=htons(head_len); 70 ip->ip_len=head_len; 71 ip->ip_id=htons(getpid()); 72 ip->ip_off=0; 73 ip->ip_ttl=MAXTTL; 74 ip->ip_p=IPPROTO_UDP; 75 ip->ip_sum=0; 76 ip->ip_dst.s_addr=addr.sin_addr.s_addr; 77 cout<<"send to ip is:"<<inet_ntoa(addr.sin_addr)<<endl; 78 ip->ip_src.s_addr=inet_addr("123.123.123.123"); 79 80 udp=(struct udphdr*)(buffer+sizeof(struct ip)); 81 udp->source=htons(addr.sin_port); 82 udp->dest=htons(addr.sin_port); 83 udp->source=addr.sin_port; 84 udp->dest=addr.sin_port; 85 cout<<"send to port is:"<<addr.sin_port<<endl; 86 udp->len=htons(sizeof(struct udphdr)+300); 87 udp->check=0; 88 char *t_buffer=buffer+sizeof(struct ip)+sizeof(struct udphdr); 89 strcpy(t_buffer,"Hello World! This is primordial!"); 90 91 int ret; 92 ret=sendto(sock_primordial,buffer,head_len,0,(struct sockaddr*)&addr,sizeof(struct sockaddr_in)); 93 perror("sendto"); 94 cout<<"ret is:"<<ret<<endl; 在Delphi 下,可否实现? 怎么关闭服务器 TADOdataset不能更新的问题! Delphi7的多语言对应问题(特急) ^_^我是一名大四学生,我想找到一份软件开发的工作,可是没有工作经验,我该怎么办呢? 问一个简单问题: 我看过好多软件里面都使用 STRINGGRID 控件,如何实现点击 fixedrow 时,可以进行排序? 怎么在也存在的数据库上增加字段(ODBC)??? 急!急!急!关于findwindow的问题???? [讯问]Delphi和Win32窗口的问题 怎样在TREEVIEW中的子树上右键弹出菜单? 进来的不要笑我啊,看的类似的帖子好多了 关于截获网卡的IP数据包的问题
if((sock_primordial=socket(AF_INET,SOCK_RAW,IPPROTO_RAW))==-1)
53 {
54 cout<<"create sock error!"<<endl;
55 }
56
57 int on=1;
58 if(setsockopt(sock_primordial, IPPROTO_IP,IP_HDRINCL,&on,sizeof(on))== -1)
59 {
60 cout<<"set sock opt error!"<<endl;
61 }
62
63 bzero(buffer,IP_TOTAL_SIZE);
64
65 ip=(struct ip *)buffer;
66 ip->ip_v=IPVERSION;
67 ip->ip_hl=5;
68 ip->ip_tos=0;
69 ip->ip_len=htons(head_len);
70 ip->ip_len=head_len;
71 ip->ip_id=htons(getpid());
72 ip->ip_off=0;
73 ip->ip_ttl=MAXTTL;
74 ip->ip_p=IPPROTO_UDP;
75 ip->ip_sum=0;
76 ip->ip_dst.s_addr=addr.sin_addr.s_addr;
77 cout<<"send to ip is:"<<inet_ntoa(addr.sin_addr)<<endl;
78 ip->ip_src.s_addr=inet_addr("123.123.123.123");
79
80 udp=(struct udphdr*)(buffer+sizeof(struct ip));
81 udp->source=htons(addr.sin_port);
82 udp->dest=htons(addr.sin_port);
83 udp->source=addr.sin_port;
84 udp->dest=addr.sin_port;
85 cout<<"send to port is:"<<addr.sin_port<<endl;
86 udp->len=htons(sizeof(struct udphdr)+300);
87 udp->check=0;
88 char *t_buffer=buffer+sizeof(struct ip)+sizeof(struct udphdr);
89 strcpy(t_buffer,"Hello World! This is primordial!");
90
91 int ret;
92 ret=sendto(sock_primordial,buffer,head_len,0,(struct sockaddr*)&addr,sizeof(struct sockaddr_in));
93 perror("sendto");
94 cout<<"ret is:"<<ret<<endl;
在Delphi 下,可否实现?