setup rwhois (?)
This commit is contained in:
parent
3e8e5fba8f
commit
00d9cbf64f
|
@ -0,0 +1,53 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const RWhoisPort = "4321"
|
||||
|
||||
func handleConnection(conn net.Conn) {
|
||||
defer conn.Close()
|
||||
|
||||
reader := bufio.NewReader(conn)
|
||||
query, err := reader.ReadString('\n')
|
||||
if err != nil {
|
||||
log.Printf("Error reading query: %v", err)
|
||||
return
|
||||
}
|
||||
query = strings.TrimSpace(query)
|
||||
log.Printf("Received query: %s", query)
|
||||
|
||||
// In a real RWhois server, you would parse the query,
|
||||
// look up data, and potentially issue referrals.
|
||||
// For this example, we'll send a simple response.
|
||||
response := fmt.Sprintf("RWhois response for: %s\n", query)
|
||||
_, err = conn.Write([]byte(response))
|
||||
if err != nil {
|
||||
log.Printf("Error writing response: %v", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
listener, err := net.Listen("tcp", ":"+RWhoisPort)
|
||||
if err != nil {
|
||||
log.Fatalf("Error listening: %v", err)
|
||||
}
|
||||
defer listener.Close()
|
||||
|
||||
log.Printf("RWhois server listening on port %s", RWhoisPort)
|
||||
|
||||
for {
|
||||
conn, err := listener.Accept()
|
||||
if err != nil {
|
||||
log.Printf("Error accepting connection: %v", err)
|
||||
continue
|
||||
}
|
||||
go handleConnection(conn)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue