Ver Mensaje Individual
  #3  
Antiguo 26-03-2007
Avatar de seoane
[seoane] seoane is offline
Miembro Premium
 
Registrado: feb 2004
Ubicación: A Coruña, España
Posts: 3.717
Reputación: 24
seoane Va por buen camino
Bueno, la dll para comprobar si el puerto esta ocupado te la doy yo.
Código Delphi [-]
library Puertos;

uses
  Windows, Winsock;

{$R *.res}

type
  MIB_TCPROW = record
    dwState: DWORD;
    dwLocalAddr: DWORD;
    dwLocalPort: DWORD;
    dwRemoteAddr: DWORD;
    dwRemotePort: DWORD;
  end;
  PMIB_TCPROW = ^MIB_TCPROW;

  MIB_TCPTABLE = record
    dwNumEntries: DWORD;
    table: array[0..0] of MIB_TCPROW;
  end;
  PMIB_TCPTABLE = ^MIB_TCPTABLE;

function GetTcpTable(pTcpTable: PMIB_TCPTABLE; var pdwSize: DWORD;
  bOrder: BOOL): DWORD; stdcall; external 'iphlpapi.dll';

function EstaOcupado(Puerto: Integer): BOOL; stdcall;
var
  TcpTable: PMIB_TCPTABLE;
  Size, i: DWORD;
begin
  Result:= FALSE;
  GetMem(TcpTable,sizeof(MIB_TCPTABLE));
  Size:= 0;
  if GetTcpTable(TcpTable, Size, TRUE) = ERROR_INSUFFICIENT_BUFFER then
  begin
    FreeMem(TcpTable);
    GetMem(TcpTable,Size);
  end;
  try
    if (GetTcpTable(TcpTable, Size, TRUE) = NO_ERROR) then
      for i:= 0 to TcpTable.dwNumEntries - 1 do
        if (TcpTable.table[i].dwState = 2) then
          if htons(TcpTable.table[i].dwLocalPort) = Puerto then
        begin
          Result:= TRUE;
          break;
        end;
  finally
    FreeMem(TcpTable);
  end;
end;

exports EstaOcupado;

begin
end.
La librería anterior exporta la función "EstaOcupado" que devuelve TRUE si el puerto esta ocupado. Desde delphi la llamaríamos así:
Código Delphi [-]
// La declaramos
function EstaOcupado(Puerto: Integer): BOOL; stdcall; external 'Puertos.dll';

// La usamos
  ShowMessage(BoolToStr(EstaOcupado(80),TRUE));
Al parecer, según Ñuño, con Pascal Scripting se pueden llamar funciones incluidas en una dll, así que con esto debería ser suficiente para hacer lo que tu quieres.

Última edición por seoane fecha: 26-03-2007 a las 15:09:27.
Responder Con Cita