Add the list of addresses to the -list -json output

This commit is contained in:
Frank Denis 2018-03-28 12:22:37 +02:00
parent 8bedb4b01e
commit e09f0875c1
2 changed files with 18 additions and 10 deletions

View File

@ -135,7 +135,7 @@ func ExtractPort(str string, defaultPort int) int {
return port return port
} }
func StripPort(str string) string { func ExtractHost(str string) string {
if idx := strings.LastIndex(str, ":"); idx >= 0 && idx < len(str)-1 { if idx := strings.LastIndex(str, ":"); idx >= 0 && idx < len(str)-1 {
if _, err := strconv.Atoi(str[idx+1:]); err == nil { if _, err := strconv.Atoi(str[idx+1:]); err == nil {
str = str[:idx] str = str[:idx]

View File

@ -123,6 +123,7 @@ type ServerSummary struct {
Name string `json:"name"` Name string `json:"name"`
Proto string `json:"proto"` Proto string `json:"proto"`
IPv6 bool `json:"ipv6"` IPv6 bool `json:"ipv6"`
Addrs []string `json:"addrs,omitempty"`
Ports []int `json:"ports"` Ports []int `json:"ports"`
DNSSEC bool `json:"dnssec"` DNSSEC bool `json:"dnssec"`
NoLog bool `json:"nolog"` NoLog bool `json:"nolog"`
@ -311,15 +312,22 @@ func (config *Config) printRegisteredServers(proxy *Proxy, jsonOutput bool) {
for _, registeredServer := range proxy.registeredServers { for _, registeredServer := range proxy.registeredServers {
addrStr, port := registeredServer.stamp.serverAddrStr, DefaultPort addrStr, port := registeredServer.stamp.serverAddrStr, DefaultPort
port = ExtractPort(addrStr, port) port = ExtractPort(addrStr, port)
addrs := make([]string, 0)
if registeredServer.stamp.proto == StampProtoTypeDoH && len(registeredServer.stamp.providerName) > 0 { if registeredServer.stamp.proto == StampProtoTypeDoH && len(registeredServer.stamp.providerName) > 0 {
providerName := registeredServer.stamp.providerName providerName := registeredServer.stamp.providerName
port = ExtractPort(providerName, port) var host string
host, port = ExtractHostAndPort(providerName, port)
addrs = append(addrs, host)
}
if len(addrStr) > 0 {
addrs = append(addrs, ExtractHost(addrStr))
} }
serverSummary := ServerSummary{ serverSummary := ServerSummary{
Name: registeredServer.name, Name: registeredServer.name,
Proto: registeredServer.stamp.proto.String(), Proto: registeredServer.stamp.proto.String(),
IPv6: strings.HasPrefix(addrStr, "["), IPv6: strings.HasPrefix(addrStr, "["),
Ports: []int{port}, Ports: []int{port},
Addrs: addrs,
DNSSEC: registeredServer.stamp.props&ServerInformalPropertyDNSSEC != 0, DNSSEC: registeredServer.stamp.props&ServerInformalPropertyDNSSEC != 0,
NoLog: registeredServer.stamp.props&ServerInformalPropertyNoLog != 0, NoLog: registeredServer.stamp.props&ServerInformalPropertyNoLog != 0,
NoFilter: registeredServer.stamp.props&ServerInformalPropertyNoFilter != 0, NoFilter: registeredServer.stamp.props&ServerInformalPropertyNoFilter != 0,