Add brackets to IPv6 literals with standard ports (#329)

Co-authored-by: erik <fake@not.real>

https://github.com/zmap/zgrab2/pull/329
This commit is contained in:
Erik 2022-02-08 10:21:53 -05:00 committed by GitHub
parent 8dadfc8509
commit d753afcd25
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -427,9 +427,15 @@ func getHTTPURL(https bool, host string, port uint16, endpoint string) string {
} else {
proto = "http"
}
if protoToPort[proto] == port {
if protoToPort[proto] == port && strings.Contains(host, ":") {
//If the host has a ":" in it, assume literal IPv6 address
return proto + "://[" + host + "]" + endpoint
} else if protoToPort[proto] == port {
//Otherwise, just concatenate host and endpoint
return proto + "://" + host + endpoint
}
//For non-default ports, net.JoinHostPort will handle brackets for IPv6 literals
return proto + "://" + net.JoinHostPort(host, strconv.FormatUint(uint64(port), 10)) + endpoint
}