Arif widiyanto

mind, passions, spirit and hopes

Tulisan terkirim dikaitan (tagged) ‘Internet/Lan’

Delphi – Mencari tahu jenis koneksi internet

Ditulis oleh arifw di/pada Sabtu, 26 April 2008

uses
WinInet;

const
MODEM = 1;
LAN = 2;
PROXY = 4;
BUSY = 8;

function GetConnectionKind(var strKind: string): Boolean;
var
flags: DWORD;
begin
strKind := ”;
Result := InternetGetConnectedState(@flags, 0);
if Result then
begin
if (flags and MODEM) = MODEM then strKind := ‘Modem’;
if (flags and LAN) = LAN then strKind := ‘LAN’;
if (flags and PROXY) = PROXY then strKind := ‘Proxy’;
if (flags and BUSY) = BUSY then strKind := ‘Modem Busy’;
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
strKind: string;
begin
if GetConnectionKind(strKind) then
ShowMessage(strKind);
end;

Ditulis dalam Delphi, Internet/Lan, Programming | Bertanda: | Leave a Comment »

Delphi – Memanggil default email program

Ditulis oleh arifw di/pada Kamis, 24 April 2008

uses

ShellApi;

procedure TForm1.Button1Click(Sender: TObject);

var

strEmail, strSubject, strBody, Param: string;

begin

strEmail := ‘user@host.com’;

strSubject := ‘Your Subject’;

strBody := ‘Your Message Text’;

Param := ‘mailto:’ + strEmail + ‘?subject=’ + strSubject +

‘&Body=’ + strBody;

ShellExecute(Form1.Handle, ‘open’, PChar(Param), nil, nil, SW_SHOWNORMAL);

end;

Ditulis dalam Delphi, Internet/Lan, Programming | Bertanda: | Leave a Comment »

Delphi – Memulai dialup connection

Ditulis oleh arifw di/pada Kamis, 24 April 2008


uses

ShellAPI;

procedure TForm1.Button1Click(Sender: TObject);

begin

case OSVer of

VER_PLATFORM_WIN32_NT:

{connection_name = the name of the connection in “Network and

DialUp Connections”, logon = logon string, password = password string.

All are separated by spaces.}

ShellExecute(Handle, ‘open’, ‘rasdial.exe’, ‘connection_name logon password’, nil, SW_HIDE);

VER_PLATFORM_WIN32_WINDOWS:

(*

Dial Up Networking (DUN)

module:

RNAUI.DLL

command:

rundll32.exe rnaui.dll,RnaDial {name of connection to establish}

result:

displays the Connect To dialog for the passed connection

*)

ShellExecute(Handle, PChar(‘open’), PChar(‘rundll32.exe’),

PChar(‘rnaui.dll,RnaDial exact name of dialer entry TRACERT -h 1 -w 1′),nil, SW_NORMAL);

end;

end;

Ditulis dalam Delphi, Internet/Lan, Programming | Bertanda: | 2 Komentar »

Delphi – Konek ke internet

Ditulis oleh arifw di/pada Kamis, 24 April 2008


unit Unit1;

interface

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

Dialogs, StdCtrls;

type

TForm1 = class(TForm)

Button1: TButton;

Button2: TButton;

edtEntry: TEdit;

edtUser: TEdit;

edtPass: TEdit;

procedure Button1Click(Sender: TObject);

procedure Button2Click(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

var

Form1: TForm1;

implementation

uses shellapi;

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);

var

cmd, par, fil, dir: PChar;

begin

cmd := ‘open’;

fil := ‘rasdial.exe’;

par := PChar(edtEntry.Text + ‘ ‘ + edtUser.Text + ‘ ‘ + edtPass.Text);

dir := ‘C:’;

ShellExecute(Self.Handle, cmd, fil, par, dir, SW_SHOWMINNOACTIVE);

end;

procedure TForm1.Button2Click(Sender: TObject);

var

cmd, par, fil, dir: PChar;

begin

cmd := ‘open’;

fil := ‘rasdial.exe’;

par := PChar(edtEntry.Text + ‘ /DISCONNECT’);

dir := ‘C:’;

ShellExecute(Self.Handle, cmd, fil, par, dir, SW_SHOWMINNOACTIVE);

end;

end.

Ditulis dalam Delphi, Internet/Lan, Programming | Bertanda: | Leave a Comment »

Delphi – Periksa apakah Winsock enabled

Ditulis oleh arifw di/pada Kamis, 24 April 2008



uses

Winsock;

function WinsockEnabled: Boolean;

var

wsaData: TWSAData;

begin

Result := True;

case Winsock.WSAStartup($0101, wsaData) of

WSAEINVAL, WSASYSNOTREADY, WSAVERNOTSUPPORTED: Result := False;

else

Winsock.WSACleanup;

end;

end;

procedure TForm1.Button1Click(Sender: TObject);

begin

if WinsockEnabled then

ShowMessage(‘Winsock is enabled’)

else

ShowMessage(‘Winsock is disabled’);

end;


Ditulis dalam Delphi, Internet/Lan, Programming | Bertanda: | Leave a Comment »

Send a file from a TServerSocket to a TClientSocket

Ditulis oleh arifw di/pada Kamis, 24 April 2008


unit Unit1;

interface

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

Dialogs, ScktComp, StdCtrls;

type

TForm1 = class(TForm)

ClientSocket1: TClientSocket;

ServerSocket1: TServerSocket;

btnTestSockets: TButton;

procedure ClientSocket1Read(Sender: TObject; Socket: TCustomWinSocket);

procedure FormCreate(Sender: TObject);

procedure FormDestroy(Sender: TObject);

procedure ClientSocket1Disconnect(Sender: TObject;

Socket: TCustomWinSocket);

procedure ClientSocket1Connect(Sender: TObject;

Socket: TCustomWinSocket);

procedure ServerSocket1ClientConnect(Sender: TObject;

Socket: TCustomWinSocket);

procedure btnTestSocketsClick(Sender: TObject);

private

FStream: TFileStream;

{ Private-Deklarationen }

public

{ Public-Deklarationen }

end;

var

Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.ClientSocket1Read(Sender: TObject;

Socket: TCustomWinSocket);

var

iLen: Integer;

Bfr: Pointer;

begin

iLen := Socket.ReceiveLength;

GetMem(Bfr, iLen);

try

Socket.ReceiveBuf(Bfr^, iLen);

FStream.Write(Bfr^, iLen);

finally

FreeMem(Bfr);

end;

end;

procedure TForm1.FormCreate(Sender: TObject);

begin

FStream := nil;

end;

procedure TForm1.FormDestroy(Sender: TObject);

begin

if Assigned(FStream) then

begin

FStream.Free;

FStream := nil;

end;

end;

procedure TForm1.ClientSocket1Disconnect(Sender: TObject;

Socket: TCustomWinSocket);

begin

if Assigned(FStream) then

begin

FStream.Free;

FStream := nil;

end;

end;

procedure TForm1.ClientSocket1Connect(Sender: TObject;

Socket: TCustomWinSocket);

begin

FStream := TFileStream.Create(‘c:\temp\test.stream.html’, fmCreate or fmShareDenyWrite);

end;

procedure TForm1.ServerSocket1ClientConnect(Sender: TObject;

Socket: TCustomWinSocket);

begin

Socket.SendStream(TFileStream.Create(‘c:\temp\test.html’, fmOpenRead or fmShareDenyWrite));

end;

procedure TForm1.btnTestSocketsClick(Sender: TObject);

begin

ServerSocket1.Active := True;

ClientSocket1.Active := True;

end;

end.



Author: www.swissdelphicenter.ch

Ditulis dalam Delphi, Internet/Lan, Programming | Bertanda: | Leave a Comment »

Delphi – Mendapatkan IP dari suatu URL

Ditulis oleh arifw di/pada Kamis, 24 April 2008


uses

Winsock;

function IAddrToHostName(const IP: string): string;

var

i: Integer;

p: PHostEnt;

begin

Result := ”;

i := inet_addr(PChar(IP));

if i <> u_long(INADDR_NONE) then

begin

p := GetHostByAddr(@i, SizeOf(Integer), PF_INET);

if p <> nil then Result := p^.h_name;

end

else

Result := ‘Invalid IP address’;

end;

Ditulis dalam Delphi, Internet/Lan, Programming | Bertanda: | Leave a Comment »

Download a file from Internet

Ditulis oleh arifw di/pada Kamis, 24 April 2008


uses

URLMon, ShellApi;

function DownloadFile(SourceFile, DestFile: string): Boolean;

begin

try

Result := UrlDownloadToFile(nil, PChar(SourceFile), PChar(DestFile), 0, nil) = 0;

except

Result := False;

end;

end;

procedure TForm1.Button1Click(Sender: TObject);

const

SourceFile = ‘http://www.somesite.com/somefile.jpg’;

DestFile = ‘c:\somefile.jpg’;

begin

if DownloadFile(SourceFile, DestFile) then

begin

ShowMessage(‘Download succesful!’);

ShellExecute(Application.Handle, PChar(‘open’), PChar(DestFile),

PChar(”), nil, SW_NORMAL)

end

else

ShowMessage(‘Error while downloading ‘ + SourceFile)

end;

Ditulis dalam Delphi, Internet/Lan, Programming | Bertanda: | Leave a Comment »