-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaclearn.cpp
More file actions
65 lines (62 loc) · 1.42 KB
/
maclearn.cpp
File metadata and controls
65 lines (62 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <iostream>
#include <dirent.h>
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
using namespace std;
#include<gtest/gtest.h>
TEST(MACLEARN,MacLearn1)
{
FILE *file = fopen("testbed.csv","r");
FILE *stream = NULL;
char rbuf[4096];
char cbuf[1024];
memset(rbuf,0,4096);
fread(rbuf,4096,1,file);
char *ipstr = strstr(rbuf,"server,");
char *ip = NULL;
if(ipstr != NULL){
ipstr += strlen("server,");
ip = ipstr;
while(*ipstr != '\n')
ipstr++;
*ipstr = '\0';
}
sprintf(cbuf,"sshpass -p roothello ssh root@%s ifconfig |grep ether|awk -F' ' '{print $2}'|line -n 1 2>&1",ip);
stream = popen(cbuf,"r");
memset(rbuf,0,4096);
int len = fread(rbuf,sizeof(char),sizeof(rbuf),stream);
for(int i = 0; i<len; i++){
rbuf[i] = toupper(rbuf[i]);
}
char mac[128];
sprintf(mac,"%s",rbuf);
//printf("%s",mac);
sprintf(cbuf,"show mac");
stream = popen(cbuf,"r");
memset(rbuf,0,4096);
fread(rbuf,sizeof(char),sizeof(rbuf),stream);
char *p = strstr(rbuf,mac);
printf("1:%s:",rbuf);
printf("2:%s:",mac);
if(p == NULL){
ASSERT_FALSE(1==1);
}
#if 0
char *p = strstr(rbuf,"Platform");
if(p == NULL){
ASSERT_FALSE(1==1);
return;
}
p[strlen("Platform")] = 0;
sprintf(cbuf,"Platform");
ASSERT_STREQ(p,cbuf);
#endif
}