Pregunta: | 21509 - COMO OBTENGO EL NOMBRE DE LA PC Y LA URL ACTIVA O ACTIVAS |
Autor: | Omar Sánchez Serrato |
Ya he intentado con la API GetComputerName pero devuelve un nombre erroneo. |
Respuesta: | jorge luis guzman abreu |
Con esta función:
function GetComputerName : String; var pcComputer : PChar; dwCSize : DWORD; begin dwCSize := MAX_COMPUTERNAME_LENGTH + 1; GetMem( pcComputer, dwCSize ); try if Windows.GetComputerName( pcComputer, dwCSize ) then Result := pcComputer; finally FreeMem( pcComputer ); end; end; Ejemplo de llamada: Label2.Caption:=GetComputerName; ---------------------------------------------------- La tor pregunta es esta: Si enviamos un "GET" al puerto 80 del servidor WEB, nos devolverá algo parecido a esto: HTTP/1.0 200 OK Date: Fri, 18.Feb 2000 09:42:29 GMT Server: Apache/1.3.6 (Unix) <=== Esta es la parte interesante Connection: close Transfer-Encoding: chunked Content-Type: text/html ... ... Codigo HTML ... La peticion como tal debe ser de la forma: GET / HTTP/1.0{CR/LF}{CR/LF}{CR/LF} El ejemplo es el sgte. <liAñade a la forma un TClientSocket, un TMemo, un TEdit y un TButton. <liEn el evento Conect del TClientSocket, pon este codigo: procedure TForm1.ClientSocket1Connect(Sender: TObject; Socket: TCustomWinSocket); begin Caption := 'Conectado'; {Connected} ClientSocket1.Socket.SendText('GET / HTTP/1.0'+#13+#10+#13+#10+#13+#10); end; -en el evento Read del ClientSocket: procedure TForm1.ClientSocket1Read(Sender: TObject; Socket: TCustomWinSocket); begin Memo1.Lines.Add(ClientSocket1.Socket.ReceiveText); end; -Y en el OnClick del Boton procedure TForm1.Button1Click(Sender: TObject); begin ClientSocket1.Host := Edit1.Text; ClientSocket1.Port := 80; ClientSocket1.Open; end; Ejecuta el programa, y en el edit escribe la direccion del servidor que desees chequear ej. 'www.q3.nu' , 'www.altavista.com', etc. Si lo quieres por direccion IP entonces en vez de ClientSocket1.Host pones ClientSocket1.Address Para 'www.q3.nu' saldra algo parecido a esto... HTTP/1.1 200 OK Date: Thu, 24 Feb 2000 21:00:41 GMT Server: Apache 1.3.6 Skyport Version Server built May 4 1999 20:10:57 |