Solved

Detect IP number change

Posted on 2003-12-05
5
435 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

863 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

20 Experts available now in Live!

Get 1:1 Help Now