06-14-2023, 07:36 AM
HI,
I have a problem. When I enter my program, the first thing I do is find out what my external IP is. For that I use a function that I saw from another programmer.
The problem is that depending on the computer, connection, times you enter the program......, sometimes it does it instantly and sometimes it takes a long time to get it (1 minute or more).
Can anyone think of how to set a timer so that if it hasn't responded in, say, 3 seconds, then program continues at another line? or by presing a key if is more easy?
Tanks
I have a problem. When I enter my program, the first thing I do is find out what my external IP is. For that I use a function that I saw from another programmer.
The problem is that depending on the computer, connection, times you enter the program......, sometimes it does it instantly and sometimes it takes a long time to get it (1 minute or more).
Can anyone think of how to set a timer so that if it hasn't responded in, say, 3 seconds, then program continues at another line? or by presing a key if is more easy?
Tanks
Code: (Select All)
Dim miip As String
Cls: Locate 10, 20: Print "COSULTING PUBLIC IP ...."
miip = GetPublicIP
Locate 10, 20: Print "PUBLIC IP: "; miip
continue:
'----- Program
End
Function GetPublicIP$
Dim URL As String
Dim URLFile As String
Dim publicip As String
Dim a%
URLFile = "publicip"
URL = "https://api.ipify.org/"
a% = FileDownload(URL, URLFile)
Dim U As Integer
U = FreeFile
Open URLFile For Binary As #U
If LOF(U) <> 0 Then
Line Input #U, publicip
Else
Close #U
Kill URLFile
GetPublicIP = ""
Exit Function
End If
Close #U
Kill URLFile
GetPublicIP = publicip
End Function
Declare Dynamic Library "urlmon"
Function URLDownloadToFileA (ByVal pCaller As Long, szURL As String, szFileName As String, Byval dwReserved As Long, Byval lpfnCB As Long)
End Declare
Function FileDownload (URL As String, File As String)
FileDownload = URLDownloadToFileA(0, URL, File, 0, 0)
End Function