+ Reply to Thread
Results 1 to 6 of 6

Obtain external IP address with VBA

  1. #1
    Registered User
    Join Date
    09-24-2009
    Location
    Spain
    MS-Off Ver
    Excel 2007
    Posts
    4

    Obtain external IP address with VBA

    I want to get the external IP address of a PC running an Excel spreadsheet. 'External IP address' meaning the public IP used to access the Internet.

    I found some code ( http://www.mvps.org/access/api/api0067.htm ) that returns the IPs bound to a machine.

    But this is not what I am looking for, as it will return a private address when the computer is behind a NAT.

    Any help or pointers really appreciated.

    Josep

  2. #2
    Registered User
    Join Date
    09-24-2009
    Location
    Spain
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Obtain external IP address with VBA

    I thought some more about the problem, and I see there are a couple of web sites:
    http://whatismyip.org/
    http://whatismyip.com/automation/n09230945.asp

    they both return the public IP address of the computer making the request.

    So, let me re-state my question: how can I retrieve a website from Excel VBA and get the content?

    Thanks,

  3. #3
    Forum Contributor
    Join Date
    09-22-2009
    Location
    Indianapolis, Indiana
    MS-Off Ver
    Office 2003 / Office 2007
    Posts
    114

    Re: Obtain external IP address with VBA

    Record a macro, run a webquery on the site that you want to use to get your IP Address, and then edit the code as needed.

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Obtain external IP address with VBA

    Hello Jose77,

    It isn't clear to me what you want when you say "content". Your first post centers around the IP address of the host. Then in your second post you say...
    So, let me re-state my question: how can I retrieve a website from Excel VBA and get the content?
    I am guessing you want the IP address for a given URL. This macro will do that. There is one annoyance. The Command screen is visible while it is running. It closes when the macro finishes, but it does work.
    Please Login or Register  to view this content.
    Example
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  5. #5
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Obtain external IP address with VBA

    If on the other it is simply a case of getting the IP of the current PC (generated by the whatismyip website) then

    Quote Originally Posted by marzuk
    Record a macro, run a webquery on the site that you want to use to get your IP Address, and then edit the code as needed.
    which would give you something like:

    Please Login or Register  to view this content.
    The above is basically automating the following process in XL2007:

    -- Go to the Data section on the Ribbon
    -- From Web
    -- Enter URL of Interest and Go
    -- Select appropriate table you wish to retrieve
    -- Click Import
    -- Follow prompts

    In the code I only changed one default setting which was to use Overwrite prior data rather than Delete and Insert new.

  6. #6
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,239

    Re: Obtain external IP address with VBA

    If you are behind a proxy/ISA server, then you could also run your original code against the gateway machine name rather than the machine with the workbook.
    Remember what the dormouse said
    Feed your head

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1