吵吵   2011-03-03  阅读:2,839

这个是用delphi写的我们学校的流量监控的软件,每隔五分钟,上校园网去读取一次流量信息,然后通过整合计算,得到最终的数据。这个可以一直开着,看看流量会不会有异常情况,碰到学校不计算流量的时候,嘿嘿,就拼命下东西吧。



unit 吵吵流量查询
interface//www.chaochaoblog.com

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
IdHTTP,inifiles,strUtils, ExtCtrls;

type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
IdHTTP1: TIdHTTP;
Label4: TLabel;
Timer1: TTimer;
Timer2: TTimer;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Timer3: TTimer;
Label9: TLabel;
Label10: TLabel;
Timer4: TTimer;
procedure FormCreate(Sender: TObject);

procedure Timer1Timer(Sender: TObject);
procedure Timer2Timer(Sender: TObject);
procedure FormDblClick(Sender: TObject);
procedure Timer3Timer(Sender: TObject);
procedure Timer4Timer(Sender: TObject);
procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
procedure FormMouseLeave(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
ifile:Tinifile;
liuliangall:int64;
liuliangbegin:int64;
cat:integer;

implementation

{$R *.dfm}

procedure Getliuliang ;
var
postURL:string;
postList:tstringlist;
response:tStringStream;

namestart:int64;
nameover:int64;
wangye:string;
wangliuliangstart,wangliuliangover:int64;
liuliangstart,liuliangover:int64;
usermoneystart,usermoneyover:int64;
wangliiuliang:string;
gangliuliang:string;

liulianglast:int64;
username:string;
userpass:string;

begin

application.ProcessMessages ;
ifile:=tinifile.Create(ExtractFileDir(Application.ExeName)+'\user.ini');
username:=ifile.ReadString('user','username','');
userpass:=ifile.ReadString('user','userpass','');
liuliangbegin:=strtoint(ifile.ReadString('user','FlowRateBegin',''));
ifile.Free;
if (username='') or(userpass='') then exit;

response:=tstringstream.Create ;
postlist:=tstringlist.Create ;

postlist.Add('userName='+username);
postlist.Add('passWord='+userpass);
//postlist.Add('ddlSF=学生');
postURL:= 'http://account.fimmu.edu.cn:8080/billsys_v3/client/querybill/querybillform.jsp' ;
try
application.ProcessMessages ;
form1.IdHTTP1.Post(postURL,postlist,response);
except
showmessage('未联网或账号或者密码错误');
exit;
end;

postURL:= 'http://account.fimmu.edu.cn:8080/billsys_v3/client/querybill/querybill.jsp';
postlist.clear;
postlist.add('queryYear='+formatdatetime('yyyy',now));
postlist.Add('queryMonth='+formatdatetime('mm',now)) ;
application.ProcessMessages ;
form1.IdHTTP1.Post(postURL,postlist,response);
form1.IdHTTP1.Disconnect;
postlist.Destroy;
wangye:=response.DataString;
response.Destroy;
application.ProcessMessages ;

namestart:= pos('用户姓名',wangye);
delete(wangye,1,namestart);
namestart:= pos('#0000FF',wangye)+9;
nameover:= pos('

',wangye);
form1.label5.Caption :=copy(wangye,namestart,nameover-namestart);
application.ProcessMessages ;

wangliuliangstart:=pos('网关流量',wangye);

delete(wangye,1,wangliuliangstart+10);

wangliuliangstart:=pos('

 

 

',wangye)+5;

wangliuliangover:=pos('

',wangye);
wangliiuliang:=copy(wangye,wangliuliangstart,wangliuliangover-wangliuliangstart);
wangliiuliang:=stringreplace(wangliiuliang,',','',);
application.ProcessMessages ;
liuliangstart:=pos('802.1x流量',wangye);
delete(wangye,1,liuliangstart+13);
liuliangstart:=pos(' liuliangover:=pos('1024*1024 then
begin
form1.label6.Caption :=inttostr(liuliangall div(1024*1024))+'M';
end
else
begin
form1.label6.Caption:=inttostr(liuliangall)+'字节';
end;

if liulianglast>1024*1024 then
begin
form1.label7.Caption := inttostr(liulianglast div (1024*1024))+'M';
end
else
begin
form1.label7.Caption :=inttostr(liulianglast)+'字节';

end;

application.ProcessMessages ;
usermoneystart:=pos('querypay.jsp?userName=',wangye);
delete(wangye,1,usermoneystart);
usermoneystart:=pos('

',wangye);
delete(wangye,1,usermoneystart+4);
usermoneystart:=pos('

 

 

 ',wangye)+4;
usermoneyover:=pos('

',wangye);
form1.label8.Caption :=copy(wangye,usermoneystart,usermoneyover-usermoneystart);

if cat=1 then
begin

form1.Timer4.Enabled :=false;
form1.Label10.Caption :='0字节';
end
else
begin
form1.Timer4.Enabled :=true;
end;
//开始获取数据

end;

procedure TForm1.FormCreate(Sender: TObject);//吵吵发布
var
hr:thandle;
begin
cat:=0;
hr:=createroundrectrgn(0,0,form1.Width ,form1.Height ,2,2);
setwindowrgn(handle,hr,true);

form1.Left :=(screen.Width -form1.Width) div 2 ;
form1.top :=0;
SetWindowLong(Handle,GWL_EXSTYLE, WS_EX_TOOLWINDOW);
setwindowpos(form1.Handle,HWND_TOPMOST,form1.Left ,form1.Top ,form1.Width ,form1.Height ,SWP_NOSIZE);
showmessage('本软件吵吵所写,请勿私自传播!(419388920)');
end;

procedure TForm1.FormDblClick(Sender: TObject);
begin
application.Terminate ;
end;

procedure TForm1.FormMouseLeave(Sender: TObject);
begin
form1.Top:=2-form1.Height ;
end;

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin

form1.Top :=0;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
form1.Top :=0;
getliuliang;
cat:=2;
timer3.Enabled :=true;
end;

procedure TForm1.Timer2Timer(Sender: TObject);

begin
timer2.Enabled :=false;
cat:=1;

getliuliang;
ifile:=tinifile.Create(ExtractFileDir(Application.ExeName)+'\user.ini');

ifile.WriteString('user','FlowRateBegin',inttostr(liuliangall));
timer3.Enabled :=true;
end;

procedure TForm1.Timer3Timer(Sender: TObject);
begin
if form1.Top =0 then
begin
form1.Top:=2-form1.Height ;
end
else
begin
form1.Top :=0;
end;

end;

procedure TForm1.Timer4Timer(Sender: TObject);
var
flowratethis:int64;

begin
timer4.Enabled :=false;
flowratethis:=liuliangall-liuliangbegin;
if flowratethis>1024*1024 then
begin
label10.Caption := inttostr(flowratethis div 1048576)+'M';

end
else
begin
LABEL10.Caption :=INTTOSTR(FLOWRATETHIS)+'字节' ;
end;
end;

end.

吵吵微信朋友圈,请付款实名加入:

吵吵 吵吵

发表评论

电子邮件地址不会被公开。 必填项已用*标注