473,883 Members | 1,599 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How To Get External IP Address via VB/VBA

2 New Member
This uses HTML scraping of this site:
http://whatismyipaddre ss.com/

Code can be changed to work with other sites if you're comfortable with String manipulation

Paste this into a Module and run.

Cheers!

Trip

Expand|Select|Wrap|Line Numbers
  1. Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
  2. Dim tempString As String
  3.  
  4. Public Function DownloadFile(URL As String, LocalFilename As String) As Boolean
  5.  
  6.     Dim lngRetVal As Long
  7.     lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
  8.     If lngRetVal = 0 Then DownloadFile = True
  9.  
  10. End Function
  11.  
  12. Sub WhatsMyIP()
  13.  
  14.     Dim StartingPoint As Long
  15.     Dim EndPoint As Long
  16.     Dim i As Integer
  17.     Dim IPAddress As String
  18.  
  19.     DownloadFile "http://whatismyipaddress.com/", "c:\tempfile.txt"
  20.  
  21.     Open "c:\tempfile.txt" For Random As #1 Len = 30000
  22.     Get #1, 1, tempString
  23.     Close #1
  24.     StartingPoint = InStr(1, tempString, """LOOKUPADDRESS"" value=""", vbTextCompare)
  25.     StartingPoint = StartingPoint + Len("""LOOKUPADDRESS"" value=""")
  26.     EndPoint = InStr(1, Mid(tempString, StartingPoint, 25), """ max", vbTextCompare)
  27.     IPAddress = Mid(tempString, StartingPoint, EndPoint - 1)
  28.     MsgBox "Your External IP Address is: " & IPAddress
  29.  
  30. End Sub
  31.  
  32.  
May 25 '12 #1
0 62026

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

Similar topics

8
4806
by: codecraig | last post by:
hi, how can i use python to figure the ip address of the machine which the python script is running on? I dont mean like 127.0.0.1....but i want the external IP address (such as ipconfig on windows displays). any ideas?? THanks
1
2003
by: S. van Beek | last post by:
Dear reader, In case an application is ussing an external model library you have to address this external model library in your application. This addressing takes place in a module of the application by opening of a module and activates and than brows to the location of the external library.
3
7592
by: Demetri | last post by:
How do I find out what the network IP address is? For example if I have a cable modem with 68.57.200.50 as the IP address and the linksys router assigns PC's on the network 192.168.1.1 how do I find out that the address is 68.57.200.50 running my code on the PC with the IP address assigned to it by the router of 192.168.1.1 ? Make sense what I'm asking? I like using WMI but if there is another way I'm willing to listen.
9
2319
by: Chris | last post by:
How do I find and print to screen the IP address of the computer my python program is working on?
4
2525
by: iwdu15 | last post by:
Hi, im using this code to get a computers IPAddress Net.Dns.GetHostEntry(Net.Dns.GetHostName()).AddressList(0) but that only gets the Lan IPAddress....how can i get the internet IP address? -- -iwdu15
1
2545
by: Abdulla Herzallah | last post by:
Hi everyone I don't know if I am posting this to the right newsgroup but it is the closest I found, in case you think you can advice me to another newsgroup please feel free to do so. I am so desperate to get my problem solved. The issue is related to sockets and networking this is my problem short version: I need to connect to an application using a specific IP, i.e. the server I will connect to will see that specific IP address
3
3311
by: Abdulla Herzallah | last post by:
Hi everyone I don't know if I am posting this to the right newsgroup but it is the closest I found, in case you think you can advice me to another newsgroup please feel free to do so. I am so desperate to get my problem solved. The issue is related to sockets and networking this is my problem short version: I need to connect to an application using a specific IP, i.e. the server I will connect to will see that specific IP address
6
5088
by: paal.andreassen | last post by:
I have a problem. I have two instances of a client-server application running on two different machines A and B. A has a listening service, that listens for connections from B B has a listening service, that listens for connections from A The problem is what IP to bind the listening service to. I can find all local ip-addresses this way:
5
2066
by: Timothy Grant | last post by:
On Tue, Aug 5, 2008 at 2:50 PM, David York <davideyork@gmail.comwrote: I'm not sure what you are trying to accomplish. The machine I'm typing this on has a 192.168.x.x number. The router that gave it to me also has a 192.168.x.x number. However, I know that that is not the IP that the world sees when my packets finally leave the building. What if your machine has multiple interface cards in it? What are you trying to accomplish?
4
13242
by: remya1000 | last post by:
i'm using VB.NET 2003 Application program. i need to get External IP Address (internet). i searched internet and found come codes and tried that... i tried this code... but it returned my internal IP Address... Dim IPHost As IPHostEntry = Dns.GetHostByName(Dns.GetHostName()) MessageBox.Show("My IP address is " & IPHost.AddressList(0).ToString()) and i tried this code too...
0
9936
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10412
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9571
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7970
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7123
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5797
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4609
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4215
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3231
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.