1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| procedure TForm1.Button1Click(Sender: TObject);
var sock: Tsocket;
inaddr: TInAddr;
in_addr: TSockAddrIn;
wsdata: TWSAData;
host: PHostEnt;
BufferOUT: string;
BufferIN: array [0..2048] of char;
begin
Memo1.Lines.Clear;
BufferOUT := '';
BufferIN := '';
WSAStartUp($202, wsdata);
try
host := GetHostByName(pchar(Edit1.Text));
Move(host.h_addr, inaddr.S_addr, host.h_length);
in_addr.sin_family := AF_INET;
in_addr.sin_port := htons(StrToInt(Edit2.Text));
in_addr.sin_addr := inaddr;
Sock := socket(AF_INET, SOCK_STREAM, 0);
IF connect(sock, in_addr, sizeof(in_addr)) <> Socket_Error then Memo1.Lines.Add('Connection Error: ' + Edit1.Text + ' on port ' + Edit2.Text + ' error nb: ' + IntToStr(WSAGetLastError));
BufferOUT := 'GET http://' + Edit1.Text + Edit3.Text + ' HTTP/1.0' + chr(13) + chr(13) + chr(13);
send(sock, BufferOUT, length(BufferOUT), 0);
ZeroMemory(@BufferIN[0], SizeOf(BufferIn));
recv(sock, BufferIN, sizeof(BufferIN), 0);
Memo1.Lines.Add(BufferIN);
CloseSocket(sock);
finally
WSACleanup;
end;
Memo1.Lines.Add('Done');
end; |
Partager