package main import ( "fmt" "net" ) func main() { conn, _ := net.Dial("tcp", "google.com:80") fmt.Println(conn.RemoteAddr().String()) }
package main import ( "fmt" "net" ) func main() { listener, _ := net.Listen("tcp", ":8080") for { conn, _ := listener.Accept() fmt.Println(conn.RemoteAddr().String()) conn.Close() } }In this example, we create a TCP listener on port 8080 using the Listen function from the net package. We then enter an infinite loop to accept connections using the Accept method. For each incoming connection, we call the RemoteAddr method on the conn variable to get the remote network address and print it to the console. Finally, we close the connection using the Close method. Package library: net.