Skip to content

Instantly share code, notes, and snippets.

@chris530
Created April 2, 2020 19:09
Show Gist options
  • Save chris530/81154de3a7e66ab55473761f97a7bc6e to your computer and use it in GitHub Desktop.
Save chris530/81154de3a7e66ab55473761f97a7bc6e to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"net"
"os"
"strconv"
"time"
)
func dns_request(c chan string, order int) {
var err error
var ip []net.IP
for i := 0; ; i++ {
//Lookup dns
ip, err = net.LookupIP("app.demandbase.com")
if err != nil {
panic(err)
}
c <- fmt.Sprintf("[%d] dns thread:%d; lookup: %s", i, order, ip)
}
}
func printer(c chan string, v int) {
for {
msg := <-c
if v == 1 {
fmt.Println(msg)
}
time.Sleep(time.Millisecond * 100)
}
}
func main() {
if os.Args[1] != "-t" {
panic("usage: ./program -t <threads> -v 1")
}
if os.Args[3] != "-v" {
panic("usage: ./program -t <threads> -v 1")
}
THREADS, _ := strconv.Atoi(os.Args[2])
VERBOSE, _ := strconv.Atoi(os.Args[4])
var thread_order int = 0
var c chan string = make(chan string)
for i := 0; i < THREADS; i++ {
go dns_request(c, thread_order)
go printer(c, VERBOSE)
thread_order++
}
var input string
fmt.Scanln(&input)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment