Hello all
I was looking for a function that returns the external ip address but or it does not exists or I was not able to find it, any hints?
External Ip Address?
External Ip Address?
----------------------------
[Allanon] Fabio Falcucci | GitHub for recent works | Support me on Patreon for Hollywood libraries | ☆★ All my links ★☆
[Allanon] Fabio Falcucci | GitHub for recent works | Support me on Patreon for Hollywood libraries | ☆★ All my links ★☆
Re: External Ip Address?
The IP protocol does not have a functionality to tell you if any devices made NAT translations of your packets. So you would need to ask a server for the IP address of your incoming packets and read it for example in form of an HTML page. I would not expect such things in a programming language.
But let's see what Andreas has to say about it.
But let's see what Andreas has to say about it.
Re: External Ip Address?
I'm using this free service right now:
https://www.ifconfig.me/ip
which returns the external ip address in plain text, seems a reliable service from what I've read on Internet.
I'm a really noob at network styff btw, thanks for the answer!
https://www.ifconfig.me/ip
which returns the external ip address in plain text, seems a reliable service from what I've read on Internet.
I'm a really noob at network styff btw, thanks for the answer!
----------------------------
[Allanon] Fabio Falcucci | GitHub for recent works | Support me on Patreon for Hollywood libraries | ☆★ All my links ★☆
[Allanon] Fabio Falcucci | GitHub for recent works | Support me on Patreon for Hollywood libraries | ☆★ All my links ★☆
Re: External Ip Address?
Using http request is typically used to retrieve external IP address programmatically. There is a faster way, you can query DNS server rather than http server.Allanon wrote: ↑Mon Apr 26, 2021 11:06 am I'm using this free service right now:
https://www.ifconfig.me/ip
which returns the external ip address in plain text, seems a reliable service from what I've read on Internet.
I'm a really noob at network styff btw, thanks for the answer!
I have not been programming with Hollywood for a while, so can't give example but here is my old 8th source (Can be a bit hard to read, if you are not used to Forth style programming languages.).
Code: Select all
net:INET4 net:DGRAM net:socket constant socket
[ 0xaa, 0xaa, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
"myip", "opendns", "com", 0x00, 0x00, 0x01, 0x00, 0x01 ] "12b1s1c1s1c1s1c5b" pack constant message
: address-info \ -- ai
"resolver1.opendns.com" 53 net:getaddrinfo ;
: app:main
address-info null? if
drop
"Server address information lookup failed." . cr
bye
then
socket swap message 0 net:sendto null? if
drop
"Error sending message.\n" .
net:close
bye
else
drop
then
512 b:new 0 net:recvfrom null? if
drop
"No response from the server\n" .
net:close
bye
then
\ Test RCODE
over 3 b:@ nip 0xf n:band not if
\ Last four bytes from the response are the IP address.
dup 4 n:- swap b:slice "4:1B" unpack drop
' >s a:map
"." a:join
"External IP: %s\n" s:strfmt .
else
2drop
"Error communicating with the server.\n" .
then
drop
net:close
bye ;
Re: External Ip Address?
Thanks for the hint, I'm not a Forth guy but I've got the idea
----------------------------
[Allanon] Fabio Falcucci | GitHub for recent works | Support me on Patreon for Hollywood libraries | ☆★ All my links ★☆
[Allanon] Fabio Falcucci | GitHub for recent works | Support me on Patreon for Hollywood libraries | ☆★ All my links ★☆
Re: External Ip Address?
This is what I use for get WAN IP of the network:
It returns the IP address in a string, or the "IP can't identify." message if failed to obtain the address.
Code: Select all
Function p_getip()
Local err=?OpenConnection (1,"checkip.dyndns.org",80)
If err=0
SendData(1,"GET index.html HTTP/1.0\r\n\r\n")
Local a$=ReceiveData(1,#RECEIVEALL)
a$=UnrightStr(a$,FindStr(a$,"<body>")+6)
a$=LeftStr(a$,FindStr(a$,"</body>"))
Return(a$)
Else
Return("IP can't identify.")
EndIf
EndFunction
- airsoftsoftwair
- Posts: 5443
- Joined: Fri Feb 12, 2010 2:33 pm
- Location: Germany
- Contact:
Re: External Ip Address?
I'm afraid there currently is no other way to get this than using one of the methods described above. Bsdsocket doesn't really have that functionality AFAICS.
Re: External Ip Address?
Thank you all, after reading a bit about this topic I've found some ways to obtain the public ip address
----------------------------
[Allanon] Fabio Falcucci | GitHub for recent works | Support me on Patreon for Hollywood libraries | ☆★ All my links ★☆
[Allanon] Fabio Falcucci | GitHub for recent works | Support me on Patreon for Hollywood libraries | ☆★ All my links ★☆