Delphi and Kylix

Moderators: pritaeas
Number of threads: 7244
Number of posts: 19051

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
IP Address Posted by rajsha on 21 Jun 2005 at 11:00 AM
How to get the primary and secondary IP of a computer?
thanx

Report
Re: IP Address Posted by zibadian on 21 Jun 2005 at 2:54 PM
: How to get the primary and secondary IP of a computer?
: thanx
:
:
You can get the IP number from the registry. It is stored under this key: HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Tcpip\Parameters\Interfaces\{71CDE3EE-CACF-4A29-A9A0-1DA5BE409C0A}
Report
Re: IP Address Posted by rajsha on 21 Jun 2005 at 8:42 PM
: : How to get the primary and secondary IP of a computer?
: : thanx
: :
: :
: You can get the IP number from the registry. It is stored under this key: HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Tcpip\Parameters\Interfaces\{71CDE3EE-CACF-4A29-A9A0-1DA5BE409C0A}
:
I did not get the key TCPIP under the specified key. I wanted to know how to get to know the dynamic IP allocated after dialing in with a dial up net connection.
Thanx
Report
Re: IP Address Posted by softman on 22 Jun 2005 at 5:59 AM
: : : How to get the primary and secondary IP of a computer?
: : : thanx
: : :
: : :
: : You can get the IP number from the registry. It is stored under this key: HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Tcpip\Parameters\Interfaces\{71CDE3EE-CACF-4A29-A9A0-1DA5BE409C0A}
: :
: I did not get the key TCPIP under the specified key. I wanted to know how to get to know the dynamic IP allocated after dialing in with a dial up net connection.
: Thanx
:
Hi!

This is a component source code, which detect's the dynamic IP. with change notification event.
I hope you can get the required information from it.

unit MyIp;

interface

uses
  SysUtils, Classes, WinSock, ExtCtrls;
type
  TMyIp = class(TComponent)
  private
    MyTim : TTimer;
    FIP: String;
    FNotifyInterval: integer;
    FHostName: string;
    FOnIpChanged: TNotifyEvent;
    FNotifyEnabled: boolean;
    procedure SetIP(const Value: String);
    function GetIp:string;
    procedure SetNotifyInterval(const Value: integer);
    procedure SetHostName(const Value: string);
    procedure MyTimeEvent(Sender : TObject);
    procedure SetOnIpChanged(const Value: TNotifyEvent);
    procedure SetNotifyEnabled(const Value: boolean);
    { Private declarations }
  protected

    { Protected declarations }
  public
  constructor Create(Owner: TComponent); override;
  destructor Destroy; override;

    { Public declarations }
  published
    property NotifyEnabled : boolean read FNotifyEnabled write SetNotifyEnabled;
    property IP:String read GetIp write SetIP;
    property NotifyInterval : integer read FNotifyInterval write SetNotifyInterval;
    property HostName : string read FHostName write SetHostName;
    property OnIpChanged : TNotifyEvent read FOnIpChanged write SetOnIpChanged;
    { Published declarations }
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('OSoft', [TMyIp]);
end;

{ TMyIp }

procedure TMyIp.SetIP(const Value: String);
begin
//  FIP := Value;
end;
function TMyIp.GetIP:String;
var
  WSAData: TWSAData;
  HostName: array[0..255] of Char;
  HostInfo: PHostEnt;
  InAddr: ^PInAddr;
begin
  if WSAStartup($0101, WSAData) = 0 then  //API Call
  try
    if gethostname(HostName, SizeOf(HostName)) = 0 then
    begin
      HostInfo := gethostbyname(HostName);
      FHostName:=HostName;
      if HostInfo <> nil then  //if hostinfo points to somewhere
      begin
        InAddr := Pointer(HostInfo^.h_addr_list); //address shown by the pointer
        if (InAddr <> nil) then   //it is our IP 
          while InAddr^ <> nil do //good for detect all IP's
          begin                   //(etc. you have more netw.cards)
            Result :=(inet_ntoa(InAddr^^));
            Inc(InAddr);
          end;
      end;
    end;
  finally              //Close winsock
    WSACleanup;        //It is very important!!!
  end;
  FIP := Result;
end;
constructor TMyIp.Create(Owner: TComponent);
begin
inherited Create(Owner);
GetIp;
MyTim := TTImer.Create(self);
MyTim.Enabled := false;
MyTim.OnTimer := MyTimeEvent;
NotifyInterval := MyTim.Interval;
end;
destructor TMyIp.Destroy;
begin
MyTim.Enabled := false;
MyTim.Free;
inherited;
end;
procedure TMyIp.SetNotifyInterval(const Value: integer);
begin
  FNotifyInterval := Value;
  MyTim.Interval := Value;
end;

procedure TMyIp.SetHostName(const Value: string);
begin
//  FHostName := Value;
end;
procedure TMyIp.MyTimeEvent(Sender : TObject);
var
  oldip : string;
begin
//
oldip := FIP;
GetIp;
if oldip <> FIP then
  if Assigned(FOnIpChanged) then FOnIpChanged(Self);
end;
procedure TMyIp.SetOnIpChanged(const Value: TNotifyEvent);
begin
  FOnIpChanged := Value;
end;

procedure TMyIp.SetNotifyEnabled(const Value: boolean);
begin
  FNotifyEnabled := Value;
  MyTim.Enabled := Value;
end;

end.



\\///
/O O\
| | |
| _ |
\___/
SoftMan

Report
Re: IP Address Posted by rajsha on 25 Jun 2005 at 8:34 PM
: : : : How to get the primary and secondary IP of a computer?
: : : : thanx
: : : :
: : : :
: : : You can get the IP number from the registry. It is stored under this key: HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Tcpip\Parameters\Interfaces\{71CDE3EE-CACF-4A29-A9A0-1DA5BE409C0A}
: : :
: : I did not get the key TCPIP under the specified key. I wanted to know how to get to know the dynamic IP allocated after dialing in with a dial up net connection.
: : Thanx
: :
: Hi!
:
: This is a component source code, which detect's the dynamic IP. with change notification event.
: I hope you can get the required information from it.
:
:
: unit MyIp;
: 
: interface
: 
: uses
:   SysUtils, Classes, WinSock, ExtCtrls;
: type
:   TMyIp = class(TComponent)
:   private
:     MyTim : TTimer;
:     FIP: String;
:     FNotifyInterval: integer;
:     FHostName: string;
:     FOnIpChanged: TNotifyEvent;
:     FNotifyEnabled: boolean;
:     procedure SetIP(const Value: String);
:     function GetIp:string;
:     procedure SetNotifyInterval(const Value: integer);
:     procedure SetHostName(const Value: string);
:     procedure MyTimeEvent(Sender : TObject);
:     procedure SetOnIpChanged(const Value: TNotifyEvent);
:     procedure SetNotifyEnabled(const Value: boolean);
:     { Private declarations }
:   protected
: 
:     { Protected declarations }
:   public
:   constructor Create(Owner: TComponent); override;
:   destructor Destroy; override;
: 
:     { Public declarations }
:   published
:     property NotifyEnabled : boolean read FNotifyEnabled write SetNotifyEnabled;
:     property IP:String read GetIp write SetIP;
:     property NotifyInterval : integer read FNotifyInterval write SetNotifyInterval;
:     property HostName : string read FHostName write SetHostName;
:     property OnIpChanged : TNotifyEvent read FOnIpChanged write SetOnIpChanged;
:     { Published declarations }
:   end;
: 
: procedure Register;
: 
: implementation
: 
: procedure Register;
: begin
:   RegisterComponents('OSoft', [TMyIp]);
: end;
: 
: { TMyIp }
: 
: procedure TMyIp.SetIP(const Value: String);
: begin
: //  FIP := Value;
: end;
: function TMyIp.GetIP:String;
: var
:   WSAData: TWSAData;
:   HostName: array[0..255] of Char;
:   HostInfo: PHostEnt;
:   InAddr: ^PInAddr;
: begin
:   if WSAStartup($0101, WSAData) = 0 then  //API Call
:   try
:     if gethostname(HostName, SizeOf(HostName)) = 0 then
:     begin
:       HostInfo := gethostbyname(HostName);
:       FHostName:=HostName;
:       if HostInfo <> nil then  //if hostinfo points to somewhere
:       begin
:         InAddr := Pointer(HostInfo^.h_addr_list); //address shown by the pointer
:         if (InAddr <> nil) then   //it is our IP 
:           while InAddr^ <> nil do //good for detect all IP's
:           begin                   //(etc. you have more netw.cards)
:             Result :=(inet_ntoa(InAddr^^));
:             Inc(InAddr);
:           end;
:       end;
:     end;
:   finally              //Close winsock
:     WSACleanup;        //It is very important!!!
:   end;
:   FIP := Result;
: end;
: constructor TMyIp.Create(Owner: TComponent);
: begin
: inherited Create(Owner);
: GetIp;
: MyTim := TTImer.Create(self);
: MyTim.Enabled := false;
: MyTim.OnTimer := MyTimeEvent;
: NotifyInterval := MyTim.Interval;
: end;
: destructor TMyIp.Destroy;
: begin
: MyTim.Enabled := false;
: MyTim.Free;
: inherited;
: end;
: procedure TMyIp.SetNotifyInterval(const Value: integer);
: begin
:   FNotifyInterval := Value;
:   MyTim.Interval := Value;
: end;
: 
: procedure TMyIp.SetHostName(const Value: string);
: begin
: //  FHostName := Value;
: end;
: procedure TMyIp.MyTimeEvent(Sender : TObject);
: var
:   oldip : string;
: begin
: //
: oldip := FIP;
: GetIp;
: if oldip <> FIP then
:   if Assigned(FOnIpChanged) then FOnIpChanged(Self);
: end;
: procedure TMyIp.SetOnIpChanged(const Value: TNotifyEvent);
: begin
:   FOnIpChanged := Value;
: end;
: 
: procedure TMyIp.SetNotifyEnabled(const Value: boolean);
: begin
:   FNotifyEnabled := Value;
:   MyTim.Enabled := Value;
: end;
: 
: end.
: 
: 

:
: \\///
: /O O\
: | | |
: | _ |
: \___/
: SoftMan
:
:
Thanks for the help!
Report
Re: IP Address Posted by jobromedia on 3 Jan 2006 at 3:05 PM
Hey thanks for the sourcecode, this might help IPlicious alot on the way.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.