program computername;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Classes , Windows , Wininet
{ you can add units after this };
//http://www.delphibasics.info/home/delphibasicssnippets/getcomputername
function myComputerName():String;
var
ComputerName: Array [0 .. 256] of char;
Size: DWORD;
begin
Size := 256;
GetComputerName(ComputerName, Size);
Result := ComputerName;
end;
function myIPAddress() : String ;
var
pSession : HINTERNET;
hFile : HINTERNET;
Size: DWORD;
buffer: array[1..1024] of byte;
bytesRead: DWORD;
begin
pSession := InternetOpen(nil, INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
hFile := InternetOpenUrlA(pSession,'http://ip.thaddy.com/',nil,0,INTERNET_FLAG_RELOAD,0);
InternetReadFile(hFile,@buffer,SizeOf(buffer),bytesRead);
buffer[Size];
end;
begin
Writeln('My computers name is : ',myComputerName());
Writeln('My computers IP is : ',myIPAddress());
ReadLn();
end.