Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4. "fmt"
  5. "net"
  6. "os"
  7. "strconv"
  8. )
  9.  
  10. type ScanResult struct {
  11. Success bool
  12. Port int
  13. Err error
  14. }
  15.  
  16. func scan(port int, host string) ScanResult {
  17. conn, err := net.Dial("tcp", fmt.Sprintf("%v:%v", host, port))
  18. result := ScanResult {
  19. Port: port,
  20. Success: err == nil,
  21. Err: err,
  22. }
  23. if conn != nil {
  24. conn.Close()
  25. }
  26. return result
  27. }
  28.  
  29. func show_usage() {
  30. fmt.Println("USAGE: ./goscanner.exe <IP> <MIN_PORT> <MAX_PORT>")
  31. }
  32.  
  33.  
  34. func main() {
  35. args := os.Args
  36.  
  37. if len(args) != 4 {
  38. show_usage()
  39. os.Exit(0)
  40. } else {
  41. min, _ := strconv.Atoi(args[2])
  42. max, _ := strconv.Atoi(args[3])
  43. for min <= max {
  44. if scan(min, args[1]).Success == true {
  45. fmt.Printf("OPEN %d\n", min)
  46. } else {
  47. fmt.Printf("CLOSED %d\n", min)
  48. }
  49. min += 1
  50. }
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement