Last active
April 21, 2021 17:17
-
-
Save dat-boris/51f42ed243f4af69e572ed10d2370b69 to your computer and use it in GitHub Desktop.
Looking at difference between port listening with/ without loopback address
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"os" | |
"net" | |
"log" | |
"time" | |
) | |
func main() { | |
port := os.Args[1] | |
withAddr, _ := net.Listen("tcp", fmt.Sprintf("127.0.0.1:%s", port)) | |
withoutAddr, err := net.Listen("tcp", fmt.Sprintf(":%s", port)) | |
if err != nil { | |
log.Panic("%v", err) | |
} | |
fmt.Printf("With address: %v\n", withAddr) | |
fmt.Printf("Without address: %v\n", withoutAddr) | |
fmt.Println("Sleeping for 100 secs...") | |
time.Sleep(100 * time.Second) | |
if withAddr != nil { | |
withAddr.Close() | |
} | |
if withoutAddr != nil { | |
withoutAddr.Close() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment