IP Address - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

IP Address

rajsharajsha Posts: 75Member
How to get the primary and secondary IP of a computer?
thanx

Comments

  • zibadianzibadian Posts: 6,349Member
    : 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_MACHINESYSTEMControlSet001ServicesTcpipParametersInterfaces{71CDE3EE-CACF-4A29-A9A0-1DA5BE409C0A}
  • rajsharajsha Posts: 75Member
    : : 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_MACHINESYSTEMControlSet001ServicesTcpipParametersInterfaces{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
  • softmansoftman Posts: 157Member
    : : : 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_MACHINESYSTEMControlSet001ServicesTcpipParametersInterfaces{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.

    [code]
    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.

    [/code]

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

  • rajsharajsha Posts: 75Member
    : : : : 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_MACHINESYSTEMControlSet001ServicesTcpipParametersInterfaces{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.
    :
    : [code]
    : 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.
    :
    : [/code]
    :
    : \///
    : /O O
    : | | |
    : | _ |
    : ___/
    : SoftMan
    :
    :
    Thanks for the help!
  • jobromediajobromedia Posts: 168Member
    Hey thanks for the sourcecode, this might help IPlicious alot on the way.
Sign In or Register to comment.