-
Notifications
You must be signed in to change notification settings - Fork 2
/
interactive.cpp
executable file
·128 lines (122 loc) · 4.11 KB
/
interactive.cpp
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
* File: interactive.cpp
* Author: Zhang Xijin(mfs6174)
* Email: [email protected]
*
* Copyright (C) 2011 Zhang Xijin(mfs6174)
*
* This file is part of XDnetmon.
*
* XDnetmon is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* XDnetmon is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XDnetmon. If not, see <http://www.gnu.org/licenses/>.
*/
#include "include.h"
#include "h.h"
extern Shezhi shezhi;
void pfhelp()
{
cout<<endl<<"用法:netmon 选项"<<endl<<endl;
cout<<"-d 网络设备名 指定网络设备 双网卡网关应指定对内网卡 不指定将使用第一个"<<endl;
cout<<"-w 开启数据包内容嗅探过滤"<<endl;
cout<<"-o 1,2,3输出模式 屏幕输出(默认) html网页 csv表格"<<endl;
cout<<"-i 秒数 指定写数据库的频率 默认为30s"<<endl;
cout<<"-t 秒数 指定流量记录的时间片宽度 时间片内的流量只计算总量 单位秒 默认600s"<<endl;
cout<<"-n 关闭速度记录 减小数据库存储空间占用"<<endl;
cout<<"-f 文件 使用自定义的内网ip数据文件 具体文件格式见后 默认使用内置的过滤器"<<endl;
cout<<" 内网ip数据文件格式如下:第一行,s或g,代表单机模式或网关模式.第二行,本机的网段 本机网段的mask.后面每一行为除本机网段外的内网网段和mask"<<endl;
cout<<"-s 保存设置 否则参数只对本次运行有效"<<endl;
cout<<"-h 打印本帮助信息"<<endl;
cout<<"-p 进入交互打印结果模式"<<endl<<endl;
cout<<"每行一条命令 以go结束 输入q退出 "<<endl;
cout<<"-m [MAC] -i [IP] -b [begintime] -e [endtime] -v -V go"<<endl;
cout<<"按顺序输入或不输入:查询指定MAC 查询指定IP 指定时间范围 显示详细记录(否则显示总和) 显示速度"<<endl;
}
void prout(bool fmac,string mac,bool fip,string ip,bool fbt,string bt,bool fet,string et,bool vb)
{
string csql;
char **rr=NULL;
if (!fbt)
bt="0";
if (!fet)
et="2147483647";
if (vb)
csql="SELECT mac,ip,data/1024/1024.0,end FROM flow ";
else
csql="SELECT mac,ip,sum(data)/1024/1024.0,end FROM flow ";
csql=csql+"WHERE ";
csql+="(start>"+bt+") ";
csql+="AND (end<"+et+") ";
if (fmac)
csql+="AND mac='"+mac+"' ";
if (fip)
csql+="AND ip='"+ip+"'";
csql+=" GROUP BY mac;";
int ii=0,i,j,hang=0,lie=0;
rr=sqlqr(csql,hang,lie);
string html="<html> <head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /> <meta http-equiv=\"Refresh\" content=\"2;url=result.html\"><link rel=\"stylesheet\" type=\"text/css\" media=\"all\" href=\"css/style.css\" /> <title>netmon result</title> </head> <body> <table> <tr>";
for (i=1;i<=lie;i++)
html+="<td>"+string(rr[ii++])+"</td>";
for (i=1;i<=hang;i++)
{
html+="</tr> <tr>";
for (j=1;j<=lie;j++)
html+="<td>"+string(rr[ii++])+"</td>";
}
if (rr!=NULL)
sqlite3_free_table(rr);
html+="</tr> </table> </body> </html>";
ofstream ouf("result.html");
ouf<<html<<endl;
}
void itof()
{
string ss,mac,ip,bt,et;
bool vb,fmac,fip,fbt,fet;
while(1)
{
cin>>ss;
if (ss[0]=='q')
break;
vb=fmac=fip=fbt=fet=false;
while (ss!="go")
{
switch(ss[1])
{
case 'm':
cin>>mac;
fmac=true;
break;
case 'i':
cin>>ip;
fip=true;
break;
case 'b':
cin>>bt;
fbt=true;
break;
case 'e':
cin>>et;
fet=true;
break;
case 'v':
vb=true;
break;
default:
cout<<"命令错误,无效输入,本行输入被抛弃"<<endl;
}
cin>>ss;
}
prout(fmac,mac,fip,ip,fbt,bt,fet,et,vb);
//prout(false,'s',false,'s',false,1,false,1,false);
}
}