如何监听本机某一个进程或者端口发送与接受的信息? 很多时候,我总是对本机上的某些应用程序向服务器发送了什么很感兴趣,并且常想过如果能修改发送的信息或者能自己分析接受到的信息将是多么有趣的事情,但我不知道要如何解决这个问题……要用什么控件,应该不用接触到数据链路层什么的吧…… 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 串口通讯的监听(for GPS)unit frmComm;interfaceusesWindows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,StdCtrls, ComCtrls,GeoUtils,GeoGPS;const MAXBLOCK = 160;typeTComm = recordidComDev : THandle;fConnected : Boolean;end;TCommForm = class(TForm)ComboBox1: TComboBox;Button1: TButton;StatusBar1: TStatusBar;Button2: TButton;ComboBox2: TComboBox;procedure Button1Click(Sender: TObject);procedure Button2Click(Sender: TObject);procedure FormClose(Sender: TObject; var Action: TCloseAction);private{ Private declarations }public{ Public declarations }end;TCommThread = Class(TThread)protectedprocedure Execute;override;publicconstructor Create;end;varCommForm: TCommForm;CommHandle : THandle;Connected : Boolean;CommThread : TCommThread;implementation{$R *.DFM}usesfrmMain,frmMdiMapView;procedure TCommThread.Execute;vardwErrorFlags,dwLength : DWORD;ComStat : PComStat;fReadStat : Boolean;InChar : Char;AbIn : String;XX,YY : double; //经度、纬度VID : string; //车号beginwhile Connected do beginGetMem(ComStat,SizeOf(TComStat));ClearCommError(CommHandle, dwErrorFlags, ComStat);if (dwErrorFlags > 0) then beginPurgeComm(CommHandle,(PURGE_RXABORT and PURGE_RXCLEAR));// return 0;end;dwLength := ComStat.cbInQue;if (dwLength>0) then beginfReadStat := ReadFile(CommHandle, InChar, 1,dwLength, nil);if (fReadStat) then beginif (InChar <> Chr(13)) and (Length(abIn) < MAXBLOCK+5 ) then AbIn := AbIn + InCharelse begin...{接收完毕,}end;//if (fReadStat>0){end; //if (dwLength>0){FreeMem(ComStat);end;{while}end;constructor TCommThread.Create;beginFreeOnTerminate := TRUE;inherited Create(FALSE); //Createsuspended = falseend;//procedure TCommForm.Button1Click(Sender: TObject);varCommTimeOut : TCOMMTIMEOUTS;DCB : TDCB;fRetVal : Boolean;beginStatusBar1.SimpleText := '连接中...';CommHandle := CreateFile(PChar(ComboBox1.Text),GENERIC_READ,0,nil,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL, 0);if CommHandle = INVALID_HANDLE_VALUE then beginStatusBar1.SimpleText := '连接失败';Exit;end;StatusBar1.SimpleText := '已同端口 '+ ComboBox1.Text + ' 连接!';CommTimeOut.ReadIntervalTimeout := MAXDWORD;CommTimeOut.ReadTotalTimeoutMultiplier := 0;CommTimeOut.ReadTotalTimeoutConstant := 0;SetCommTimeouts(CommHandle, CommTimeOut);GetCommState(CommHandle,DCB);DCB.BaudRate := 9600;DCB.ByteSize := 8;DCB.Parity := NOPARITY;DCB.StopBits := ONESTOPBIT;fRetVal := SetCommState(CommHandle, DCB);if (fRetVal) then beginConnected := TRUE;tryCommThread := TCommThread.Create;exceptConnected := FALSE;CloseHandle(CommHandle);fRetVal := FALSE;StatusBar1.SimpleText := '线程建立失败';Exit;end;endelse beginConnected := FALSE;CloseHandle(CommHandle);end;end;procedure TCommForm.Button2Click(Sender: TObject);beginConnected := FALSE;CloseHandle(CommHandle);{终止线程}CommThread.Terminate;StatusBar1.SimpleText := '关闭端口'+ComboBox1.Text;end;procedure TCommForm.FormClose(Sender: TObject; var Action: TCloseAction);beginConnected := FALSE;CloseHandle(CommHandle);StatusBar1.SimpleText := '关闭端口'+ComboBox1.Text;end;end. 这个程序是For GPS的,能不能适用于别的程序呢?或者说这个程序本来是万能的,只是现在用来监视GPS?我更想知道监听的原理…… 书中有云:建立一个WinSock,用Listen()来监听,连接信息,然后就能用Recv来读取信息,问题是,我要如何伪装成这个程序来给服务器发送信息呢?能有两个进程使用同一个进程吗?而且,我在读取信息后,原来的进程会不会接收不了该信息呢?还有很多问题,不过这两个是比较主要的…… 能不能屏蔽控件的句柄 winexec命令执行第一次可以,以后就不行,请指点 ****如何解决多个客户同时操作一条记录的问题? 怎样屏蔽掉DBGridEh的第二列,使之不能让用户编辑,并且不能得到焦点 哪里有DELPHI的反编译程序? 如何控制修改dbedit字段内容的长短? 关于拖普,华为的评论 DCOM的连接速度问题!100重谢! 特急!!!!在Delphi如何获取局域网客户的IP地址 ? Indy组件使用时,除了要开scktsrvr.exe以外,还要什么? 调用函数 500分!!!ie编程的超难的古怪问题,问过多人未果。请高手相助!
unit frmComm;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,StdCtrls, ComCtrls,GeoUtils,GeoGPS;const MAXBLOCK = 160;type
TComm = record
idComDev : THandle;
fConnected : Boolean;
end;TCommForm = class(TForm)ComboBox1: TComboBox;
Button1: TButton;
StatusBar1: TStatusBar;
Button2: TButton;
ComboBox2: TComboBox;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;TCommThread = Class(TThread)protected
procedure Execute;override;
public
constructor Create;end;varCommForm: TCommForm;
CommHandle : THandle;
Connected : Boolean;
CommThread : TCommThread;implementation{$R *.DFM}uses
frmMain,frmMdiMapView;procedure TCommThread.Execute;
var
dwErrorFlags,dwLength : DWORD;
ComStat : PComStat;
fReadStat : Boolean;
InChar : Char;
AbIn : String;
XX,YY : double; //经度、纬度
VID : string; //车号
begin
while Connected do begin
GetMem(ComStat,SizeOf(TComStat));
ClearCommError(CommHandle, dwErrorFlags, ComStat);
if (dwErrorFlags > 0) then begin
PurgeComm(CommHandle,(PURGE_RXABORT and PURGE_RXCLEAR));
// return 0;
end;
dwLength := ComStat.cbInQue;
if (dwLength>0) then begin
fReadStat := ReadFile(CommHandle, InChar, 1,dwLength, nil);
if (fReadStat) then begin
if (InChar <> Chr(13)) and (Length(abIn) < MAXBLOCK+5 ) then AbIn := AbIn + InChar
else begin
...
{接收完毕,}
end;//if (fReadStat>0){
end; //if (dwLength>0){
FreeMem(ComStat);
end;{while}
end;
constructor TCommThread.Create;
begin
FreeOnTerminate := TRUE;
inherited Create(FALSE); //Createsuspended = false
end;
//procedure TCommForm.Button1Click(Sender: TObject);
var
CommTimeOut : TCOMMTIMEOUTS;
DCB : TDCB;
fRetVal : Boolean;
begin
StatusBar1.SimpleText := '连接中...';
CommHandle := CreateFile(PChar(ComboBox1.Text),GENERIC_READ,0,nil,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL, 0);
if CommHandle = INVALID_HANDLE_VALUE then begin
StatusBar1.SimpleText := '连接失败';
Exit;
end;
StatusBar1.SimpleText := '已同端口 '+ ComboBox1.Text + ' 连接!';
CommTimeOut.ReadIntervalTimeout := MAXDWORD;
CommTimeOut.ReadTotalTimeoutMultiplier := 0;
CommTimeOut.ReadTotalTimeoutConstant := 0;
SetCommTimeouts(CommHandle, CommTimeOut);
GetCommState(CommHandle,DCB);
DCB.BaudRate := 9600;
DCB.ByteSize := 8;
DCB.Parity := NOPARITY;
DCB.StopBits := ONESTOPBIT;
fRetVal := SetCommState(CommHandle, DCB);
if (fRetVal) then begin
Connected := TRUE;
try
CommThread := TCommThread.Create;
except
Connected := FALSE;
CloseHandle(CommHandle);
fRetVal := FALSE;
StatusBar1.SimpleText := '线程建立失败';
Exit;
end;
end
else begin
Connected := FALSE;
CloseHandle(CommHandle);
end;
end;procedure TCommForm.Button2Click(Sender: TObject);
begin
Connected := FALSE;
CloseHandle(CommHandle);
{终止线程}
CommThread.Terminate;
StatusBar1.SimpleText := '关闭端口'+ComboBox1.Text;
end;procedure TCommForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Connected := FALSE;
CloseHandle(CommHandle);
StatusBar1.SimpleText := '关闭端口'+ComboBox1.Text;
end;end.
或者说这个程序本来是万能的,只是现在用来监视GPS?我更想知道监听的原理……