用C语言想编一个程序,在dos的循环输入arp -d 命令,应该如何编?
用system调用。
即
while(1)
{
system(“arp -d”);
}
这样就可以了
c语言读取arp的报文txt文件的特定行的特定字节,急,在线等!
#include stdio.h
//#include string.h
const int MAXLINES = 1000;
const int MAXLEN = 200;
// 将info[]中的 oldch 替换为 newch
void replace(char info[], char oldch, char newch) {
int i = 0;
while(info[i]) {
if(info[i] == oldch) info[i] = newch;
++i;
}
}
int main() {
int n = 0;
char info[MAXLINES][MAXLEN],discard[MAXLEN];
FILE *infp;
char filename[60];
printf(“文件名:”);
scanf(“%s”,filename);
if((infp = fopen(filename,”rt”)) == NULL) {
printf(“不能打开数据文件:%s\n”,filename);
return 1;
}
while(fgets(discard,MAXLEN,infp) n MAXLINES) { // 读取空行
fgets(discard,MAXLEN,infp); // 读取时间等信息行
fscanf(infp,”%s”,discard); // 读取|0
fgets(info[n++],MAXLINES ,infp); // 读取有用信息,注意,最后的有效字符可能是’\n’
}
fclose(infp);
return 0;
}
关于C语言指针定义的问题
a是行指针,也就是指向一个包含3个int一维数组的指针(地址就是指针,a是指针常量,p是指针变量)。你要将a赋值给p,就要用行指针来接,所以你声明的p是指向一个包含3个int的指针p;如果声明的是int
*p,p就是指向int的指针,数据类型不匹配。
输出的话,可以这样p[i][j],上面说了,a,p都是地址,a能做的,p就能,只是说p是可变的,a不是。
当然你可以强转:
int*p;
p=(int*)a;
但是这样的话你的p是,指向int的指针,
输出就不能那样了,改为:
printf(“%d”,*(p+3*i+j));
或者
printf(“%d”,p[3*i+j]);
就是把二维当一维,直接看元素在第几个。
利用C语言编写模拟ARP发送请求数据包和接收数据包
我给你一个技术思路吧。
如果要用C实现模拟ARP发送数据包和接收数据包,可以使用VC6.0开发win32 console application,然后开发一个windows控制台程序,使用API函数开发。
C语言写ARP欺骗
#include stdafx.h
#include “iostream”
#include “fstream”
#include “string”
#include “windows.h”
#include “Iphlpapi.h”
#pragma comment(lib , “IpHlpApi.lib”)
#pragma comment(lib , “ws2_32.lib”)
#define MACFILE “mac.ini” //mac配置文件
#define GATEWAY “gateway.ini”//网关地址文件
using namespace std;
int main(int argc,char * argv[])
{
string ipadd;
string macadd;
char bc;
//读取网关ip地址
fstream _ipadd;
_ipadd.open(GATEWAY,ios::in);
while(_ipadd.get(bc))
{
ipadd+=bc;
}
cout “ARP欺骗检查工具 By:Neeao \n”;
cout “网关IP:” ipadd endl;
int iReturn;
DWORD dwIP;
BYTE byMAC[6];
DWORD dwLen;
WSADATA WsaData;
WSAStartup(MAKEWORD(2, 0), WsaData);
dwIP = inet_addr(ipadd.c_str());
//cout dwIP “\n”;
if (dwIP == INADDR_NONE)
{
cout “IP地址出错: ” ipadd;
return 1;
}
//循环获取mac地址
while(TRUE)
{
// 发送ARP查询包获得 MAC 地址
dwLen = 6;
iReturn = SendARP(dwIP, 0, (PULONG) byMAC, dwLen);
if (iReturn != NO_ERROR)
{
printf(“出错了:只能获取当前网关下主机的MAC地址.\n”, argv[1]);
//__leave;
return 1;
}
char MACadd[50];
sprintf(MACadd,”%.2X-%.2X-%.2X-%.2X-%.2X-%.2X”,byMAC[0],byMAC[1],byMAC[2],byMAC[3],byMAC[4],byMAC[5]);
//cout MACadd;
//判断macadd是否为空,不为空直接跳过
if(macadd==””)
{
fstream _mac;
_mac.open(MACFILE,ios::in);
if(!_mac)
{
//coutMACFILE”没有被创建”;
//第一次运行写入mac地址,为初始mac地址。
fstream _macr;
_macr.open(MACFILE,ios::out|ios::app);
if(!_macr)
{
cout”文件创建失败,磁盘不可写或者文件为只读!”;
exit(1);
}
_macr MACadd;
_macr.close();
macadd = MACadd;
}
else
{
char ch;
string content;
while(_mac.get(ch))
{
content+=ch;
}
_mac.close();
macadd = content;
cout “MAC地址为:” content endl;
}
}
//判断mac地址
if(macadd==MACadd)
{
cout “ok\n”;
//return 1;
}else
{
cout “MAC地址被修改了\n”;
//return 1;
}
Sleep(2000);//每2秒钟获取一次
}
return 0;
}