Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "fmt"
- "net"
- "os"
- "strconv"
- )
- type ScanResult struct {
- Success bool
- Port int
- Err error
- }
- func scan(port int, host string) ScanResult {
- conn, err := net.Dial("tcp", fmt.Sprintf("%v:%v", host, port))
- result := ScanResult {
- Port: port,
- Success: err == nil,
- Err: err,
- }
- if conn != nil {
- conn.Close()
- }
- return result
- }
- func show_usage() {
- fmt.Println("USAGE: ./goscanner.exe <IP> <MIN_PORT> <MAX_PORT>")
- }
- func main() {
- args := os.Args
- if len(args) != 4 {
- show_usage()
- os.Exit(0)
- } else {
- min, _ := strconv.Atoi(args[2])
- max, _ := strconv.Atoi(args[3])
- for min <= max {
- if scan(min, args[1]).Success == true {
- fmt.Printf("OPEN %d\n", min)
- } else {
- fmt.Printf("CLOSED %d\n", min)
- }
- min += 1
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement