Click here to Skip to main content
12,558,623 members (53,479 online)
Click here to Skip to main content
Add your own
alternative version


59 bookmarked

Get all IP numbers of your machine and how to pass through an authenticating proxy

, 30 Sep 2002 CPOL
Rate this:
Please Sign up or sign in to vote.
An article on how to find all IP numbers of your machine. Will also show you how to pass through an authenticating proxy server.

Sample Image - getipnr.gif


I needed some code that would give me the IP number of my machine. Not only the number assigned to it by DHCP, either on a LAN or by my ISP when dialing up, but also my IP number as seen from the web, if my machine is behind a router/firewall.

It took a while before I figured it all out, and in the process I have seen a lot of code from others. I borrowed some code here and there, but I don't remember exactly what part, so it is hard to give credits to the authors of that code. Sorry about that. Hope I can make it up by sharing this code with you.

Relevant functions in the sample source code

The sample program does essentially two things: it reports the IP numbers as 'known' by the TCP/IP software on your own machine ('internal' IP numbers) and it reports the IP numbers of your machine as seen from the web ('external' IP numbers). Of course one of the internal numbers will be the same as the external number if there is no router/firewall between your machine and the Internet.

Internal IP numbers

Internal IP numbers are reported by function FindLocalAddress(). It calls GetIpAddrTable(), one of the IP Helper functions, which returns a block of data with this structure:

typedef struct _MIB_IPADDRTABLE
    DWORD dwNumEntries;

dwNumEntries contains the number of entries in 'table'.

The structure of 'table' looks like this:

typedef struct _MIB_IPADDRROW
    DWORD        dwAddr;
    DWORD        dwIndex;
    DWORD        dwMask;
    DWORD        dwBCastAddr;
    DWORD        dwReasmSize;
    unsigned short    unused1;
    unsigned short    wType;

dwAddr is the address we are after. FindLocalAddresses() fetches that number and converts it to a string by calling function inet_ntoa().

External IP numbers

External IP numbers are reported by function FindWebAddress(). It does this by making a connection to URL ''. To see why, open this URL in your browser. It returns the IP number of your machine as seen from this site. If your machine is behind a firewall/router this number will differ from the internal IP numbers found earlier. Of course in this case the IP number found will in fact be the IP number of your router/firewall.

FindWebAddress() uses the WinINet API to make a connection to '' and to read and parse its HTML source to find the IP number hidden in this HTML source.

How to pass through an authenticating proxy server

FindWebAddress() also shows you how to pass through a proxy server that requires authentication. The sample program creates its CInternetSession object with option INTERNET_OPEN_TYPE_PRECONFIG. This means that if your Internet Explorer configuration contains a proxy server definition ("Tools - Internet Options - Connection tab - LAN Settings..."), the Internet connection will be made through this proxy server. In that case you will know that you have to pass through an authenticating proxy when your first attempt to connect to '' fails with return code 407. The sample program will then ask you to specify a username and a password, and tries to connect to '' through the proxy server.

About the author

My name is Nico Cuppen. I live in Haarlem, The Netherlands and I like programming. That's how I became a shareware author. You can find more info about me and my products on


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Nico Cuppen
Web Developer
Netherlands Netherlands
No Biography provided

You may also be interested in...


Comments and Discussions

Questioncomo diz aqui na terrinha... Pin
ans_rock@hotmail.com15-Jun-12 14:13
memberans_rock@hotmail.com15-Jun-12 14:13 
GeneralMy vote of 5 Pin
Michael Haephrati1-Feb-12 9:43
memberMichael Haephrati1-Feb-12 9:43 
GeneralThank you Pin
3box6-May-11 6:36
member3box6-May-11 6:36 
GeneralMy vote of 5 Pin
zzz7net18-Jan-11 4:59
memberzzz7net18-Jan-11 4:59 
Generalneed C# implementation Pin
Tauhid Shaikh24-Sep-07 2:16
memberTauhid Shaikh24-Sep-07 2:16 
Generalhi Pin
ji`19-Aug-07 20:39
memberji`19-Aug-07 20:39 
GeneralMessy Pin
Swinefeaster23-May-07 12:16
memberSwinefeaster23-May-07 12:16 
GeneralGetting IP Address of Local Machine Pin
paijwar6-Sep-06 4:08
memberpaijwar6-Sep-06 4:08 
Generalerror! Pin
mahila27-Dec-05 23:32
membermahila27-Dec-05 23:32 
GeneralRe: error! Pin
Nico Cuppen27-Dec-05 23:39
memberNico Cuppen27-Dec-05 23:39 
GeneralRe: error! Pin
mahila28-Dec-05 23:52
membermahila28-Dec-05 23:52 
GeneralRe: error! Pin
Andre Oliveira5-May-06 1:28
memberAndre Oliveira5-May-06 1:28 
Generalregarding Pin
kalicharan7-Aug-04 21:16
memberkalicharan7-Aug-04 21:16 
GeneralRe: regarding Pin
Bob Stanneveld30-Sep-04 7:16
memberBob Stanneveld30-Sep-04 7:16 
GeneralNeed compiled version Pin
Ed_N16-Feb-04 1:34
memberEd_N16-Feb-04 1:34 
GeneralRe: Need compiled version Pin
Nico Cuppen17-Feb-04 2:29
memberNico Cuppen17-Feb-04 2:29 
Generalerrors with iphlpapi.h Pin
M00sejewce11-Feb-04 4:52
memberM00sejewce11-Feb-04 4:52 
GeneralRe: errors with iphlpapi.h Pin
Nico Cuppen17-Feb-04 2:32
memberNico Cuppen17-Feb-04 2:32 
GeneralRe: errors with iphlpapi.h Pin
Duncan_Aitken16-Apr-04 1:05
memberDuncan_Aitken16-Apr-04 1:05 
GeneralRe: errors with iphlpapi.h Pin
Anonymous29-Jan-05 2:54
sussAnonymous29-Jan-05 2:54 
GeneralRe: errors with iphlpapi.h Pin
Anonymous3-Aug-04 12:18
sussAnonymous3-Aug-04 12:18 
GeneralRe: errors with iphlpapi.h Pin
Planlos5-Aug-04 22:36
sussPlanlos5-Aug-04 22:36 
GeneralRe: errors with iphlpapi.h Pin
Anonymous30-Nov-04 9:49
sussAnonymous30-Nov-04 9:49 
GeneralRe: errors with iphlpapi.h Pin
Anonymous8-Dec-04 2:34
sussAnonymous8-Dec-04 2:34 
GeneralRe: errors with iphlpapi.h Pin
Apollo823-Sep-08 10:27
memberApollo823-Sep-08 10:27 
GeneralRe: errors with iphlpapi.h Pin
send_jk10-Jul-06 20:55
membersend_jk10-Jul-06 20:55 
GeneralNetwork Monitoring Pin
Chechi15-Dec-03 0:52
memberChechi15-Dec-03 0:52 
GeneralRe: Network Monitoring Pin
Nico Cuppen15-Dec-03 1:13
memberNico Cuppen15-Dec-03 1:13 
GeneralQuestion Pin
nonahelmi30-Jul-03 16:00
membernonahelmi30-Jul-03 16:00 
GeneralRe: Question Pin
Anonymous10-Sep-03 21:24
sussAnonymous10-Sep-03 21:24 
GeneralRe: Question Pin
mystro_AKA_kokie21-Oct-03 11:21
membermystro_AKA_kokie21-Oct-03 11:21 
General30-40 second delay Pin
Anonymous27-Feb-03 3:36
sussAnonymous27-Feb-03 3:36 
GeneralRe: 30-40 second delay Pin
mYkel12-May-04 5:07
membermYkel12-May-04 5:07 
GeneralTimely ... Thanks Pin
Michael Patrick3-Oct-02 5:00
memberMichael Patrick3-Oct-02 5:00 
Generalerror Pin
Anonymous1-Oct-02 21:14
sussAnonymous1-Oct-02 21:14 
GeneralRe: error Pin
Nico Cuppen1-Oct-02 23:07
memberNico Cuppen1-Oct-02 23:07 
GeneralBroken Link... Pin
Daniel Madden1-Oct-02 8:11
memberDaniel Madden1-Oct-02 8:11 
GeneralRe: Broken Link... Pin
Michael Mac1-Oct-02 9:43
memberMichael Mac1-Oct-02 9:43 
GeneralRe: Broken Link... Pin
Nico Cuppen1-Oct-02 11:12
memberNico Cuppen1-Oct-02 11:12 
GeneralRe: Broken Link... Pin
Michael Mac1-Oct-02 20:29
memberMichael Mac1-Oct-02 20:29 
GeneralRe: Broken Link... Pin
Nishant S1-Oct-02 22:42
editorNishant S1-Oct-02 22:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.161026.1 | Last Updated 1 Oct 2002
Article Copyright 2002 by Nico Cuppen
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid