|
{
|
|
adtos 1.6 Software de gestión de Aulas Tecnológicas
|
|
Copyright (C) 2008-2009, Consejería de Educación,Junta de Extremadura
|
|
Programación: Manuel Narváez Martínez <mnarvaez007@gmail.com>
|
|
Diseño gráfico: Ana María Zamora Moreno
|
|
Desarrollado con Lazarus 0.9.26
|
|
|
|
This program 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 2 of the License, or
|
|
(at your option) any later version.
|
|
This program 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 this program; if not, write to the Free Software
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
}
|
|
unit clpingCliente;
|
|
|
|
interface
|
|
|
|
uses
|
|
globales,SysUtils,Classes, IdComponent, IdTCPClient; //unix
|
|
|
|
|
|
type
|
|
TdatEqu=record
|
|
usuario:String;
|
|
nombre:String;
|
|
mac:String;
|
|
ip:String;
|
|
Encendido:integer;
|
|
datos:String
|
|
end;
|
|
|
|
{ ThrPingCliente }
|
|
|
|
ThrPingCliente = class(TThread)
|
|
private
|
|
fusuario: TIdTCPClient;
|
|
fcliente: TIdTCPClient;
|
|
ftsEquiposAlumnos:TStringList;
|
|
fdatosprofe:String;
|
|
fdequipos:Array of TdatEqu;
|
|
function ObtenerPuerto(myip: string): integer;
|
|
protected
|
|
procedure Execute; override;
|
|
|
|
public
|
|
constructor Create(const datosEquiposA:TArray_datos_equipos;datosprofe:string);
|
|
end;
|
|
implementation
|
|
constructor ThrPingCliente.Create(const datosEquiposA:TArray_datos_equipos;datosprofe:string);
|
|
var
|
|
i:integer;
|
|
begin
|
|
inherited Create(true);
|
|
SetLength(fdequipos,Length(datosEquiposA));
|
|
for i:= 0 to High(datosEquiposA) do
|
|
begin
|
|
|
|
fdequipos[i].nombre:=datosEquiposA[i].nombre;
|
|
fdequipos[i].ip:=datosEquiposA[i].ip;
|
|
fdequipos[i].mac:=datosEquiposA[i].mac;
|
|
fdequipos[i].usuario:=' ';
|
|
fdequipos[i].Encendido:=0;
|
|
fdequipos[i].datos:='';
|
|
end;
|
|
fdatosProfe:=datosprofe;
|
|
self.FreeOnTerminate:=True;
|
|
|
|
end;
|
|
function ThrPingCliente.ObtenerPuerto(myip:string):integer;
|
|
const
|
|
ORDEN_IP:string='echo %s | cut -f4 -d"."';
|
|
var
|
|
miequipo1:string;
|
|
finalport:integer;
|
|
ordp:string;
|
|
begin
|
|
try
|
|
finalport:=99;
|
|
try
|
|
ordp:=Format(ORDEN_IP,[myip]);
|
|
miequipo1:=HallarDato(ordp);
|
|
finalport:=strtoint(miequipo1)
|
|
except
|
|
finalport:=99;
|
|
end;
|
|
finally
|
|
result:=37000+finalport;
|
|
end;
|
|
end;
|
|
procedure ThrPingCliente.Execute;
|
|
var
|
|
puerto,j,i:integer;
|
|
begin
|
|
try
|
|
ftsEquiposAlumnos:=TStringList.Create();
|
|
for j:=0 to 1 do
|
|
begin
|
|
for i :=0 to High(fdequipos) do
|
|
begin
|
|
if (fdequipos[i].Encendido=1) then continue;
|
|
try
|
|
fcliente:=TIdTCPClient.Create();
|
|
try
|
|
fdequipos[i].datos:=fdequipos[i].nombre+'&'+fdequipos[i].ip+'&'+fdequipos[i].mac+'& &0';
|
|
fcliente.Host:=fdequipos[i].ip;
|
|
fcliente.port:=36999;
|
|
fcliente.ConnectTimeout:=500;
|
|
fcliente.connect;
|
|
fdequipos[i].Encendido:=1;
|
|
fdequipos[i].datos:=fdequipos[i].nombre+'&'+fdequipos[i].ip+'&'+fdequipos[i].mac+'& &1';
|
|
except
|
|
if fcliente.Connected then fcliente.Disconnect();
|
|
end;
|
|
finally
|
|
if fcliente.Connected then fcliente.Disconnect();
|
|
fcliente.Free;
|
|
end;
|
|
if fdequipos[i].Encendido=1 then
|
|
begin
|
|
try
|
|
try
|
|
sleep (100);
|
|
fusuario:=TIdTCPClient.create;
|
|
puerto:=ObtenerPuerto(fdequipos[i].ip);
|
|
fusuario.Host:='localhost';
|
|
fusuario.ConnectTimeout:=500;
|
|
fusuario.port:=puerto;
|
|
fusuario.connect;
|
|
fusuario.GetResponse(200);
|
|
fusuario.SendCmd('hallarUsuario',306);
|
|
fdequipos[i].usuario:= trim(fusuario.LastCmdResult.text.text);
|
|
if trim(fdequipos[i].usuario)= '' then fdequipos[i].usuario:= ' ';
|
|
if fusuario.Connected then fusuario.Disconnect();
|
|
except
|
|
if fusuario.Connected then fusuario.Disconnect();
|
|
end;
|
|
finally
|
|
fdequipos[i].datos:=fdequipos[i].nombre+'&'+fdequipos[i].ip+'&'+fdequipos[i].mac+'&'+fdequipos[i].usuario+'&1';
|
|
fusuario.free;
|
|
end;
|
|
end;
|
|
|
|
end;
|
|
end;
|
|
finally
|
|
ftsEquiposAlumnos.Add(fdatosprofe);
|
|
for i:=0 to High(fdequipos) do
|
|
ftsEquiposAlumnos.add(fdequipos[i].datos);
|
|
g_tsEquiposAlumnos.Text:=ftsEquiposAlumnos.Text;
|
|
ftsEquiposAlumnos.Free;
|
|
Terminate;
|
|
end;
|
|
end;
|
|
|
|
end.
|
|
|