BASIC User Group > Code Challenges

Retrieve your External IP address

<< < (2/5) > >>

I hope this isn't cheating.

--- Code: Script BASIC ---IMPORT curl.bas ch = curl::init()curl::option(ch,"URL","")PRINT curl::perform(ch),"\n"curl::finish(ch) 

$ scriba
  "ip": "#4.#9.#1.#11",
  "hostname": "",
  "city": "Mount Vernon",
  "region": "Washington",
  "country": "US",
  "loc": "48.4352,-122.2080",
  "postal": "98273",
  "org": "AS33650 Comcast Cable Communications, LLC"

If you only want the ip, add a /ip to the end of the url.

$ scriba


Well, that's how it's typically done:  find a website that returns your IP. It's very simple to set that up yourself using a single line of PHP.

With that said, the challenge is to retrieve the info by querying the provided DNS server directly.


I figured my approach didn't meet the challenge requirements but it's sure is a quick way to get there.

On a positive note I might add this feature to sbhttpd  as a StatCounter like log.

The challenge illustrates a language's ability to do high or low level socket programming by interacting with a DNS server, rather than a WEB server.

The Python, Go, and 8th examples show a more high level (abstracted) approach.

I'm finalizing a low level C example, which I'll post in a bit...


I tried using SB socket OPEN but couldn't figure out how to get it to work.

Port = 53 ?

How is the resolver url passed?


[0] Message Index

[#] Next page

[*] Previous page

Go to full version