Proyecto

General

Perfil

Descargar (3,33 KB) Estadísticas
| Rama: | Revisión:
23a384b9 Elisa
unit clservidor;

{$mode objfpc}{$H+}

interface

uses
unix,Classes, SysUtils,process,clcomandosroot;
type

{ Tservidor }

Tservidor = class
private
fIP:String;
fMAC:string;
fHost:string;
fIPVLC:string;

public
constructor create ();
property IP:String read fIP;
property MAC:String read fMAC;
property Host:String read fHost;
property IPVLC:String read fIPVLC write fIPVLC;
function ObtenerMiIp():string;
function ObtenerMiMAC():string;
procedure ApagarEquipo();
function ObtenerHost():string;
procedure Ejecutar(comando: string);
function HallarDato(Cmd: string): string;
Procedure EnviarDatosEquipo();
end;

implementation

function Tservidor.ObtenerHost():string;
const
ORD_HOST:string='hostname | cut -f1 -d"."';
begin
result:=HallarDato(ORD_HOST);
end;

procedure Tservidor.Ejecutar (comando:string);
begin;
unix.fpSystem(comando);
end;

function Tservidor.HallarDato(Cmd:string):String;
var
file1: TextFile;
s,t: ansistring;
n: longint;
j:integer;
begin
j:=0;
n:=popen(file1, Cmd, 'r');
if n=-1 then
begin
result:='';
// writeln('Error al hallar dato');
Exit;
end;
t:='';
while not eof(file1) do begin
Readln(File1,s);
t:=t+s+Chr(10);
inc(j);
end;
pclose(file1);
result := trim(t);
end;
constructor Tservidor.create();
begin
inherited create;
end;

procedure Tservidor.apagarEquipo;
const
ORDEN_APAGAR:string='killall -9 ssh;/sbin/poweroff -fp &';
begin
Ejecutar(ORDEN_APAGAR);
end;


function Tservidor.ObtenerMiIp():string;
var
mip:string;
begin
try
mip:=trim(HallarDato('/sbin/ifconfig eth0 | grep "inet" | cut -f2 -d":" | cut -f1 -d" "'));
result:=mip;
except
result:='192.168.0.X';
end;
end;
function Tservidor.ObtenerMiMAC():string;
const
ORD_MAC:string='/sbin/ifconfig eth0 | grep Ethernet |head -1 | tr -s " " | cut -f5 -d" "';
begin
try
result:=trim(Hallardato(ORD_MAC));
except
result:='XX:XX:XX:XX:XX:XX';
end;
end;
Procedure TServidor.EnviarDatosEquipo();
var
mi_ip, mi_nombre, mi_mac, mis_datos, host_profe, orden_actualizar_datos:string;
begin
try
if FileExists('/usr/sbin/ethtool') then Ejecutar('/usr/sbin/ethtool -s eth0 wol g');
if FileExists('/sbin/ethtool') then Ejecutar('/sbin/ethtool -s eth0 wol g');
mi_ip:=ObtenerMiIP();
mi_mac:=ObtenerMiMAC();
mi_nombre:= ObtenerHost();
//mi_nombre:='a01-o02';
mis_datos:=mi_nombre+'&'+mi_ip+'&'+mi_mac;
host_profe:='192.168.0.254';
orden_actualizar_datos:= 'actualizarDatosEquipo '+ mis_datos;
//writeln(mis_datos);
with ThrComandosRoot.create(host_profe,311,36999,orden_actualizar_datos) do Resume;
with ThrComandosRoot.create(host_profe,311,36997,orden_actualizar_datos) do Resume;
except
// writeln('Error al hallar dato');
end;

end;



end.