Recent Posts

Pages: 1 [2] 3 4 ... 10
11
Code Challenges / Re: Retrieve your External IP address
« Last post by AIR on March 18, 2019, 11:55:16 PM »
GO:

Code: Go
  1. package main
  2.  
  3. import (
  4.         "context"
  5.         "fmt"
  6.         "log"
  7.         "net"
  8. )
  9.  
  10. func customDialer(ctx context.Context, network, address string) (net.Conn, error) {
  11.         d := net.Dialer{}
  12.         return d.DialContext(ctx, network, net.JoinHostPort("resolver1.opendns.com", "53"))
  13. }
  14.  
  15. func main() {
  16.  
  17.         r := net.Resolver{
  18.                 PreferGo: true,
  19.                 Dial:     customDialer,
  20.         }
  21.  
  22.         ipaddr, err := r.LookupHost(context.Background(), "myip.opendns.com")
  23.         if err != nil {
  24.                 log.Fatal(err)
  25.         }
  26.  
  27.         fmt.Println("External IP:", ipaddr[0])
  28. }
  29.  

AIR.
12
Code Challenges / Re: Retrieve your External IP address
« Last post by AIR on March 18, 2019, 11:52:14 PM »
PYTHON:

Code: Python
  1. #!/usr/bin/env python
  2.  
  3. import dns.resolver,socket
  4.  
  5. res = dns.resolver.Resolver(configure=False)
  6. res.nameservers = [socket.gethostbyname("resolver1.opendns.com")]
  7. print res.query('myip.opendns.com')[0]
  8.  

AIR.
13
Code Challenges / Retrieve your External IP address
« Last post by AIR on March 18, 2019, 11:49:09 PM »
Typically, when one is looking to retrieve their external IP address programmatically, one resorts to making an html request to a website like https://myexternalip.com/raw

For this challenge, the task is to retrieve your external IP using a *** DNS Query *** to resolver1.opendns.com.

The request you will send to that DNS server is: "myip.opendns.com".  The server is configured to respond to that specific request by returning the EXTERNAL IP address of the machine making the request.

Libraries, third party included, are allowed but shelling to a command line utility (like dig) or another programming language is not allowed.  Neither is scraping a webpage.

Obviously, you should NOT post your IP Address.

To test whether you are retrieving the correct IP address, either check it with the link provided at the begining of this post, or just google "my ip".

You can also check locally at a shell prompt, using:

Windows: nslookup myip.opendns.com. resolver1.opendns.com

Linux/macOS: dig +short myip.opendns.com @resolver1.opendns.com


To summarize:

DNS SERVER:   resolver1.opendns.com
DNS REQUEST: myip.opendns.com

AIR.



14
Scripting Languages / Re: SB Pi
« Last post by AIR on March 18, 2019, 07:34:39 PM »
I don't think so, I think the underlying architectures are different...only one way to find out.

Also, some of the required support libraries might not be present.
15
Scripting Languages / Re: SB Pi
« Last post by John on March 18, 2019, 06:34:40 PM »
AIR,

Do you think your Raspberry Pi AppImage of Script BASIC would run on my Samsung S8+ in a Connect Bot terminal session? I already have Busybox Linux utilities installed.

I have an Android SB I compiled native on a rooted Samsung Galaxy Tab 10.5. Getting libcurl to compile was a challenge.
16
Scripting Languages / Re: SB Pi
« Last post by John on March 18, 2019, 06:17:59 PM »
Raspberry Pi Desktop has a cool GPIO emulator with an array of sensors. It's programable using the Python examples included. Sounds like a great way to develop GPIO applications and not need the physical interface or sensor modules.
17
Code Challenges / Re: Generate QR code
« Last post by John on March 17, 2019, 09:12:14 PM »
I like the GO feature of being able to include code from the web.

I'm going to try using SB's pre-processor to acomplishish the same effect.
18
Scripting Languages / Re: SB Pi
« Last post by John on March 17, 2019, 09:08:01 PM »
Thanks AIR!

Quote
For this example Iím going to be using the standard pthreads library, a locally-compiled open-source wiringPi library, and the current C11 standard with our compile

This answers my questions about SBT and using Gordon's WiringPi library.  8)
19
Scripting Languages / Re: SB Pi
« Last post by AIR on March 17, 2019, 08:50:57 PM »
This may help get you started:

The Useful RaspberryPi Cross Compile Guide
20
Code Challenges / Re: Generate QR code
« Last post by AIR on March 17, 2019, 08:29:07 PM »
GO:

Code: Go
  1. package main
  2.  
  3. import (
  4.         "os"
  5.  
  6.         qrcode "github.com/skip2/go-qrcode"
  7. )
  8.  
  9. func main() {
  10.         err := qrcode.WriteFile("https://www.allbasic.info/forum/index.php", qrcode.Medium, 256, "qr.png")
  11.         if err != nil {
  12.                 println("Error generating QR image...")
  13.                 os.Exit(-1)
  14.         }
  15. }
  16.  
Pages: 1 [2] 3 4 ... 10