Advertisement
Guest User

tarpit.go

a guest
Jan 24th, 2020
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.88 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "log"
  5.     "net"
  6. )
  7.  
  8. // "Handle" the connection. Note: The connection is never actually closed; it just remains open forever.
  9. func handle(c net.Conn) {
  10.     b := make([]byte, 1024)
  11.     log.Printf("connection accepted from %s ", c.RemoteAddr())
  12.  
  13.     for {
  14.         // Consume all the content from the connection
  15.         _, err := c.Read(b)
  16.  
  17.         if err != nil {
  18.             log.Printf("error: %s", err.Error())
  19.  
  20.             return
  21.         }
  22.  
  23.         // Print the contnet
  24.         log.Printf("%s", b)
  25.     }
  26. }
  27.  
  28. // A dumb sinkhole.
  29. //
  30. // Works by just accepting the TCP connection but neither closing nor responding to it.
  31. //
  32. // Implemented by stubbing out the DNS server, responding with the machine running this
  33. // service .
  34. func main() {
  35.     ln, err := net.Listen("tcp", ":443")
  36.     if err != nil {
  37.         panic(err)
  38.     }
  39.  
  40.     for {
  41.         c, err := ln.Accept()
  42.  
  43.         if err != nil {
  44.             panic(err)
  45.         }
  46.  
  47.         go handle(c)
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement