示例#1
0
文件: port.go 项目: aelsabbahy/goss
// FIXME: Is there a better way to do this rather than ignoring errors?
func GetPorts(lookupPids bool) map[string][]GOnetstat.Process {
	ports := make(map[string][]GOnetstat.Process)
	netstat, _ := GOnetstat.Tcp(lookupPids)
	var net string
	//netPorts := make(map[string]GOnetstat.Process)
	//ports["tcp"] = netPorts
	net = "tcp"
	for _, entry := range netstat {
		if entry.State == "LISTEN" {
			port := strconv.FormatInt(entry.Port, 10)
			ports[net+":"+port] = append(ports[net+":"+port], entry)
		}
	}
	netstat, _ = GOnetstat.Tcp6(lookupPids)
	//netPorts = make(map[string]GOnetstat.Process)
	//ports["tcp6"] = netPorts
	net = "tcp6"
	for _, entry := range netstat {
		if entry.State == "LISTEN" {
			port := strconv.FormatInt(entry.Port, 10)
			ports[net+":"+port] = append(ports[net+":"+port], entry)
		}
	}
	netstat, _ = GOnetstat.Udp(lookupPids)
	//netPorts = make(map[string]GOnetstat.Process)
	//ports["udp"] = netPorts
	net = "udp"
	for _, entry := range netstat {
		port := strconv.FormatInt(entry.Port, 10)
		ports[net+":"+port] = append(ports[net+":"+port], entry)
	}
	netstat, _ = GOnetstat.Udp6(lookupPids)
	//netPorts = make(map[string]GOnetstat.Process)
	//ports["udp6"] = netPorts
	net = "udp6"
	for _, entry := range netstat {
		port := strconv.FormatInt(entry.Port, 10)
		ports[net+":"+port] = append(ports[net+":"+port], entry)
	}
	return ports
}
示例#2
0
文件: port.go 项目: postfix/goss
func GetPorts() map[string]map[string]string {
	ports := make(map[string]map[string]string)
	netstat := GOnetstat.Tcp(false)
	netPorts := make(map[string]string)
	ports["tcp"] = netPorts
	for _, entry := range netstat {
		if entry.State == "LISTEN" {
			port := strconv.FormatInt(entry.Port, 10)
			netPorts[port] = entry.Ip
		}
	}
	netstat = GOnetstat.Tcp6(false)
	netPorts = make(map[string]string)
	ports["tcp6"] = netPorts
	for _, entry := range netstat {
		if entry.State == "LISTEN" {
			port := strconv.FormatInt(entry.Port, 10)
			netPorts[port] = entry.Ip
		}
	}
	netstat = GOnetstat.Udp(false)
	netPorts = make(map[string]string)
	ports["udp"] = netPorts
	for _, entry := range netstat {
		port := strconv.FormatInt(entry.Port, 10)
		netPorts[port] = entry.Ip
	}
	netstat = GOnetstat.Udp6(false)
	netPorts = make(map[string]string)
	ports["udp6"] = netPorts
	for _, entry := range netstat {
		port := strconv.FormatInt(entry.Port, 10)
		netPorts[port] = entry.Ip
	}
	return ports
}