HI,
How can i find my current IP ( Provider adress delivered by my isp and no local adress) when i use Purebasic
Thnaks in advance
Current IP Adress
Re: Current IP Adress
Marc56us's code is better.
Last edited by BarryG on Fri Feb 21, 2020 12:28 pm, edited 1 time in total.
Re: Current IP Adress
Many website provide some WebService, use new PB function HTTPRequest() to query itloulou2522 wrote:How can i find my current IP ( Provider adress delivered by my isp and no local adress) when i use Purebasic

ie: https://www.ipify.org/
Need PureBasic Version >= 5.70 LTS (2nd January 2019)
Code: Select all
; Know my WAN IP
; Thanks https://www.ipify.org/
EnableExplicit
InitNetwork()
Define HttpRequest = HTTPRequest(#PB_HTTP_Get, "https://api.ipify.org/")
If HttpRequest
Debug "WAN IP: " + HTTPInfo(HTTPRequest, #PB_HTTP_Response)
FinishHTTP(HTTPRequest)
Else
Debug "Request failed"
EndIf
End
Re: Current IP Adress
The only risk to this is that we don't know how long https://api.ipify.org will allow parsing like that. They could stop it at any time, or limit the number of calls. Just something to be aware of. If you have your own website, you can set up your own PHP script to return the public IP, and it'll always be there for you. It's what I do.
The other risk is if https://api.ipify.org returns an error message (say if you're disconnected without realizing); so you need to check that an actual IP address is returned, instead of a message like "Couldn't resolve host 'api.ipify.org'".
The other risk is if https://api.ipify.org returns an error message (say if you're disconnected without realizing); so you need to check that an actual IP address is returned, instead of a message like "Couldn't resolve host 'api.ipify.org'".
-
- Always Here
- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: Current IP Adress
Hi loulou2522
Do you really need your own IP Address? If so, that's fine, as discussed by BarryG, but if your App is going to be used by others, that's a different kettle of fish. Also, some ISPs provide home Users with dynamic IP addresses, so it could be different every day.
Do you really need your own IP Address? If so, that's fine, as discussed by BarryG, but if your App is going to be used by others, that's a different kettle of fish. Also, some ISPs provide home Users with dynamic IP addresses, so it could be different every day.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
-
- Enthusiast
- Posts: 542
- Joined: Tue Oct 14, 2014 12:09 pm
Re: Current IP Adress
Wher can i find Marc56us's Code please ?BarryG wrote:Marc56us's code is better.