Created
July 12, 2012 04:49
-
-
Save flazz/3095873 to your computer and use it in GitHub Desktop.
multiple dns lookups
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// go run slurp.go rubyhq.com pythonhq.com javahq.com erlanghq.com | |
package main | |
import "net" | |
import "fmt" | |
import "os" | |
func lookup (name string, c chan string) { | |
h, err := net.LookupHost(name) | |
var answer string | |
if err == nil { | |
answer = fmt.Sprintf("%v %v", name, h) | |
} else { | |
answer = fmt.Sprintf("%v %v", name, err) | |
} | |
c <- answer | |
} | |
func main () { | |
names := os.Args[1:] | |
c := make(chan string, len(names)) | |
for _, name := range names { | |
go lookup(name, c) | |
} | |
for _ = range names { | |
answer := <-c | |
fmt.Println(answer) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// node slurp.js rubyhq.com pythonhq.com javahq.com erlanghq.com | |
var dns = require('dns'), | |
names = process.argv.slice(2); | |
names.forEach(function(name) { | |
dns.lookup(name, function(err, address) { | |
if (err === null) { | |
console.log(name + ' ' + address); | |
} else { | |
console.log(name + ' ' + err); | |
} | |
}); | |
}); |
goodfoo
commented
Jul 17, 2012
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment