Page 1 of 1
Current IP Adress
Posted: Fri Feb 21, 2020 11:43 am
by loulou2522
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
Re: Current IP Adress
Posted: Fri Feb 21, 2020 12:02 pm
by BarryG
Marc56us's code is better.
Re: Current IP Adress
Posted: Fri Feb 21, 2020 12:04 pm
by Marc56us
loulou2522 wrote:How can i find my current IP ( Provider adress delivered by my isp and no local adress) when i use Purebasic
Many website provide some WebService, use new PB function HTTPRequest() to query it
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
Posted: Fri Feb 21, 2020 12:34 pm
by BarryG
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'".
Re: Current IP Adress
Posted: Fri Feb 21, 2020 12:50 pm
by IdeasVacuum
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.
Re: Current IP Adress
Posted: Fri Feb 21, 2020 1:21 pm
by loulou2522
BarryG wrote:Marc56us's code is better.
Wher can i find Marc56us's Code please ?