Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "log"
- "net"
- )
- // "Handle" the connection. Note: The connection is never actually closed; it just remains open forever.
- func handle(c net.Conn) {
- b := make([]byte, 1024)
- log.Printf("connection accepted from %s ", c.RemoteAddr())
- for {
- // Consume all the content from the connection
- _, err := c.Read(b)
- if err != nil {
- log.Printf("error: %s", err.Error())
- return
- }
- // Print the contnet
- log.Printf("%s", b)
- }
- }
- // A dumb sinkhole.
- //
- // Works by just accepting the TCP connection but neither closing nor responding to it.
- //
- // Implemented by stubbing out the DNS server, responding with the machine running this
- // service .
- func main() {
- ln, err := net.Listen("tcp", ":443")
- if err != nil {
- panic(err)
- }
- for {
- c, err := ln.Accept()
- if err != nil {
- panic(err)
- }
- go handle(c)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement