Solved

Detect IP number change

Posted on 2003-12-05
5
433 Views
Last Modified: 2010-04-05
Hi Experts,

Is there a way to detect if windows change its IP addrerss ??

eg.
ipconfig /relaese
ipconfig /renew

If the IP address is obtained from a DHCP server the server may deliver a different address. How do i detect if this happen ??

Something like this : procedure WmSettingChange(var Msg : TWmSettingChange); message WM_SETTINGCHANGE; ??

Regards
Peter
0
Comment
Question by:PeterLarsen
  • 2
  • 2
5 Comments
 
LVL 8

Accepted Solution

by:
gmayo earned 50 total points
ID: 9883354
Just check every minute or so. If the number is different from last time, then it's changed.

Here's some code to get the list of IP addresses for your machine (you may have more than one):

procedure GetIPs(s : TStrings);
type
      TaPInAddr = Array[0..10] of PInAddr;
      PaPInAddr = ^TaPInAddr;
var
      phe : PHostEnt;
      pptr : PaPInAddr;
      Buffer : Array[0..63] of Char;
      i : Integer;
      GInitData : TWSAData;
begin
      WSAStartup($101, GInitData);
      s.Clear;
      GetHostName(Buffer, SizeOf(Buffer));
      phe := GetHostByName(buffer);
      if phe <> nil then begin
            pPtr := PaPInAddr(phe^.h_addr_list);
            I := 0;
            while pPtr^[I] <> nil do
            begin
                  s.Add(inet_ntoa(pptr^[I]^));
                  Inc(I);
            end;
            WSACleanup;
      end;
end;


Geoff M.
0
 
LVL 2

Author Comment

by:PeterLarsen
ID: 9884221
Thanks for your comment.
There must be a better way to do this.

btw. Do you know how to get the DNS entrys ?

Kind Regards
Peter
0
 
LVL 6

Expert Comment

by:MannSoft
ID: 9884237
That's the method I use in some of my utilities.  Granted I didn't search every inch of the internet, but all the sources I found indicated that it was the only way to do it.
0
 
LVL 8

Expert Comment

by:gmayo
ID: 9884242
Don't know how to get the DNS servers. Try asking that question in a new thread.

Geoff M.
0
 
LVL 2

Author Comment

by:PeterLarsen
ID: 9884556
I dont have time to search the entire net, so i will simply poll for changes - as suggested by Geoff. :-)

About DNS lookup - i have tried that but with no success (there are no simple answer to that) :-(

Kind Regards
Peter
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now