473,378 Members | 1,387 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Anyone out there have a clean Get_External_IP_Address function?

I need a function that returns the external ip address as a string for use inside a Microsoft Access application. My efforts to find one thru searching google and bing produce answers that do not work in Access/VBA.

Thanks.
Oct 17 '09 #1

✓ answered by Delerna

So in the code posted on the thread that NeoPa posted.
All you need do, if I understand the question correctly, is

1) Take that code and make a function out of it.
2) call the function and pass the address you supplied to it.
http://www.whatismyip.com/
3) Write a function that opens the text file for reading
4) Find the line (in code) that has
"<H1>Your IP Address Is: ???.???.???.???</H1>"
where ???.???.???.??? is the IP address you are after
5) voila.....I tried it and it works

Clunky...yes...but it works and is easy.


Hope I haven't spelled out the obvious here.


PS
Also, NeoPa is correct, its all very well for a web site to say
This is your IP. Sure, it's an IP relating to the request from you to their web server. But its an IP of what? It might be your router. It might be the address of one of your ISP's routers....it might be ??????

15 3924
NeoPa
32,556 Expert Mod 16PB
As there can be multiple external IP addresses, can you further clarify your requirement. I'm hoping you're not talking about your router address (The external address for your network - IE for a single home PC).

I would guess you would need to look into the Scripting libraries for this.
Oct 18 '09 #2
sites like http://www.whatismyip.com/ display my external ip address. It is this address that I am interested in grabbing via vba code in access.
Oct 18 '09 #3
NeoPa
32,556 Expert Mod 16PB
Oh dear. The address of your router then. At least your post makes it very clear what you're after.

The problem with this is that this information is neither configured into your machine nor easily (or standardly - sorry for the word invention there) enquire of your router which IP Address it is using on its external port.

It may not be totally impossible (Someone may be able to knock up some code that enquires of the link using an HTML interface or even process the response from one of the networking tools (EG. TraceRt, PathPing, etc) but this is in no way trivial. This is because what you're after is not even related to you own PC, but is an attribute of your router (and of your supplier of course, but that's equally complicated to enquire).
Oct 18 '09 #4
I saw an example of obtaining your current external ip address using vb.net but shame on me for not saving the link. If I there was a way to stream the html of a site (that rarely changes) of my choosing into a text file I could pick thru the text file to get my address. In a way I'm happy that a bytes administrator with 15000 posts is perplexed. I'd hate to ask a question that had too obvious an answer. So is there a way to capture the html of a site in VBA?
Oct 18 '09 #5
NeoPa
32,556 Expert Mod 16PB
I can understand why it would be hard for you to realise why the question isn't as straightforward as you seem to think it is. As a Networks Manager myself, I often find difficulty explaining even some of the basics of networking to those without the experience. Trust me on this one. It makes less sense than you might assume.

If we were to assume then, for the sake of this question, that you are dealing with a very straightforward, home style network, where there is a single point of connection to the outside world through a single router, then I think the web based approach, where the results of a web page are returned and sifted in your code, may well produce results. You will need to be careful if employing this technique commercially - it will almost certainly not be reliable enough - but for a home-based solution it can work.

There is a library (Microsoft HTML Object Library) that you can use. I have to admit to very little experience in this area myself, although it sounds quite a useful area to get experience in. I'm pretty sure I saw a post in a thread recently which covered this (at least in a basic way). If I find it I'll post a link in here. I'm pretty sure we do have experts who can cover this though (hence the remembered thread).
Oct 18 '09 #6
NeoPa
32,556 Expert Mod 16PB
As luck would have it, the other expert participant in that thread just posted and bumped it to the top of my subscribed threads. I hope you find this link (Output html file to text file) helpful.
Oct 18 '09 #7
Delerna
1,134 Expert 1GB
So in the code posted on the thread that NeoPa posted.
All you need do, if I understand the question correctly, is

1) Take that code and make a function out of it.
2) call the function and pass the address you supplied to it.
http://www.whatismyip.com/
3) Write a function that opens the text file for reading
4) Find the line (in code) that has
"<H1>Your IP Address Is: ???.???.???.???</H1>"
where ???.???.???.??? is the IP address you are after
5) voila.....I tried it and it works

Clunky...yes...but it works and is easy.


Hope I haven't spelled out the obvious here.


PS
Also, NeoPa is correct, its all very well for a web site to say
This is your IP. Sure, it's an IP relating to the request from you to their web server. But its an IP of what? It might be your router. It might be the address of one of your ISP's routers....it might be ??????
Oct 18 '09 #8
The address that http://www.whatismypic.com/ provides is close enough for my needs. I'll try your suggestions and piece together a function. I realize that what lies between any given PC and what the rest of the internet sees as it's IP Address may be a lot of smoke and mirrors. If writing Microsoft Access Database applications wasn't so much fun I'd consider getting really deep with that IP routing stuff. Thanks for your suggestions. There seems to be no shortage of brain power across the pond and down under.
Oct 19 '09 #9
NeoPa and Delerna,
Your suggested techniques were a success for me!

Further time on whatismyip.com suggested this site for 'scraping':
http://www.whatismyip.com/automation/n09230945.asp

Thanks again. Do you consider active participation on this site as a valid form of compenstation for your time?
Oct 19 '09 #10
ADezii
8,834 Expert 8TB
Here is a simple Routine that I put together that may/may not be of much use to you. It actually extracts IP Addresses from the Output of the IPConfig Command to a Text File via Redirection. The IP Addresses are stored in Procedural Level Variables as you will see:
Expand|Select|Wrap|Line Numbers
  1. Dim varRetVal
  2. Dim strLine As String
  3. Dim strDefaultGateway As String
  4. Dim strSubNetMask As String
  5. Dim strIPAddress As String
  6. Dim strDHCPServer As String
  7. Const conPATH_TO_FILE As String = "C:\Test\IPConfig.txt"
  8.  
  9. varRetVal = Shell("cmd.exe /c IPConfig /all > " & conPATH_TO_FILE, vbHide)
  10.  
  11. Open conPATH_TO_FILE For Input As #1
  12.  
  13. Do While Not EOF(1)
  14.   Line Input #1, strLine
  15.     If InStr(strLine, "IP Address") > 1 Then
  16.       strIPAddress = Mid$(strLine, InStr(strLine, ":") + 1)
  17.         Debug.Print "The IP Address of the Local PC is: " & strIPAddress
  18.     ElseIf InStr(strLine, "Subnet Mask") > 1 Then
  19.       strSubNetMask = Mid$(strLine, InStr(strLine, ":") + 1)
  20.         Debug.Print "The IP Address of the Subnet Mask is: " & strSubNetMask
  21.     ElseIf InStr(strLine, "Default Gateway") > 1 Then
  22.       strDefaultGateway = Mid$(strLine, InStr(strLine, ":") + 1)
  23.         Debug.Print "The IP Address of the Default Gateway is: " & strDefaultGateway
  24.     ElseIf InStr(strLine, "DHCP Server") > 1 Then
  25.       strDHCPServer = Mid$(strLine, InStr(strLine, ":") + 1)
  26.         Debug.Print "The IP Address of the DHCP Server is: " & strDHCPServer
  27.     End If
  28. Loop
  29.  
  30. Close #1    ' Close file.
Sample OUTPUT (Stand Alone PC):
Expand|Select|Wrap|Line Numbers
  1. The IP Address of the Local PC is:  192.168.1.101
  2. The IP Address of the Subnet Mask is:  255.255.255.0
  3. The IP Address of the Default Gateway is:  192.168.1.1
  4. The IP Address of the DHCP Server is:  192.168.1.1
Oct 19 '09 #11
Delerna
1,134 Expert 1GB
@mdommer1
You are very welcome and even more so because you took the time to let us know
Active participation works for me ;)
Who knows what you might say or ask that will turn out to be valuable.
Oct 19 '09 #12
Helpers:
Thanks to your suggestions here is the function that will return your current External IP Address:

Expand|Select|Wrap|Line Numbers
  1. Function GetExternalIPAddress() As String
  2. On Error GoTo GetExternalIPAddress_Error
  3.  
  4.     Dim iebrowser As InternetExplorer
  5.     Dim dtStartTime As Date
  6.     Dim sDocHTML As String
  7.     Dim strIPAddress As String
  8.  
  9.     'Create a browser object
  10.     Set iebrowser = CreateObject("internetexplorer.application")
  11.     iebrowser.Navigate "http://www.whatismyip.com/automation/n09230945.asp"
  12.  
  13.     'Wait for the page to load
  14.     dtStartTime = Now
  15.     Do While iebrowser.readyState <> READYSTATE_COMPLETE
  16.         If DateDiff("s", dtStartTime, Now) > 10 Then GoTo GetExternalIPAddress_Timeout
  17.     Loop
  18.  
  19.     'Get the page contents
  20.     sDocHTML = iebrowser.Document.documentElement.innerHTML
  21.  
  22.     'destroy the browser object
  23.     Set iebrowser = Nothing
  24.  
  25.     strIPAddress = Mid(sDocHTML, InStr(sDocHTML, "<BODY>") + 6, InStr(sDocHTML, "</BODY>") - InStr(sDocHTML, "<BODY>") - 6)
  26.  
  27. GetExternalIPAddress_Exit:
  28.     GetExternalIPAddress = strIPAddress
  29.     Exit Function
  30.  
  31. GetExternalIPAddress_Timeout:
  32.     strIPAddress = "Timeout"
  33.     GoTo GetExternalIPAddress_Exit
  34.  
  35. GetExternalIPAddress_Error:
  36.     strIPAddress = "Error"
  37.     Resume GetExternalIPAddress_Exit
  38.  
  39. End Function
  40.  
  41.  
Oct 19 '09 #13
I almost forgot.. also the reference to the "Microsoft Internet Controls" type library needs to be there.

Thanks again everybody
Oct 19 '09 #14
Adezii,
I was looking for more of how the outside world sees from the other side of a router, but thanks. Your routine is helpful to me on another project.
Oct 19 '09 #15
NeoPa
32,556 Expert Mod 16PB
@mdommer1
Absolutely. I can hardly think of better.

That, and a pleasant manner when dealing with those attempting to help you, and it seems you have that already ;) I look forward to seeing more of you :)
Oct 19 '09 #16

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Craig Thomson | last post by:
I was wondering what people do with text provided by the user in a form. Some cleaning needs to be done at some stage if you are going to be putting it in a database or displaying it etc. But when...
19
by: Leif K-Brooks | last post by:
Has anyone ever tried implementing a simple unstructured BASIC dialect in Python? I'm getting interested in language implementation, and looking at a reasonably simple example like that could be...
102
by: RFox | last post by:
I date back to the early days of the web when HTML was limited but very managable, and have always maintained that hand-coding HTML gives you far better control and cleaner HTML markup than any...
162
by: Isaac Grover | last post by:
Hi everyone, Just out of curiosity I recently pointed one of my hand-typed pages at the W3 Validator, and my hand-typed code was just ripped to shreds. Then I pointed some major sites...
15
by: lallous | last post by:
Hello, I have a function like: void fnc() { char *mem1, *mem2, *mem3, *mem4; // lots of code... // mem1, 2, 3, 4 got allocated // lots of code and condition checks if (condition_failed)
3
by: Matt Kruse | last post by:
Does anyone actively use JSUnit < http://www.edwardh.com/jsunit/ > for unit testing their javascript code? For logical functions, I imagine it could be very useful. However, I'm wondering how...
10
by: lallous | last post by:
Hello, This question was asked in comp.lang.c++ and the answers involved the use of objects whose destructors are automatically called when getting out of scope, however I was expecting...
45
by: salad | last post by:
I'm curious about your opinion on setting relationships. When I designed my first app in Access I'd go to Tools/Relationships and set the relationships. Over time I'd go into the window and see...
3
by: Doug Haber | last post by:
Hi All, I know this probably sounds pretty obvious, but lets say I have a function like: HRESULT getDevice(IWMDMDevice3* pIDevice) If it returns E_FAIL, then the pointer may be in an invalid...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.