Browse Source

fixed port not bound

Signed-off-by: gryffyn <me@neveris.one>
vlang
gryffyn 3 weeks ago
parent
commit
6b0ec81fd7
Signed by: gryffyn GPG Key ID: 6948DD6514D02BEF
  1. 21
      README.md
  2. 8
      main.go

21
README.md

@ -0,0 +1,21 @@
# port
Go application for showing port info.
## requirements
Requires netstat.
Archlinux: `net-tools`
## usage
```
§ port -h
Usage: port [--simple] PORT
Positional arguments:
PORT
Options:
--simple, -s Show simplified output (just the protocol, local address, and PID/process)
--help, -h display this help and exit
```

8
main.go

@ -23,8 +23,10 @@ func main() {
if err != nil { log.Fatalln(err) }
lines := strings.Split(string(portInfo), "\n")
found := false
for _,v := range lines {
if strings.Contains(v, ":" + strconv.Itoa(args.Port)) {
found = true
split := strings.Split(v, " ")
for _,v2 := range split {
if strings.TrimSpace(v2) != "" {
@ -34,14 +36,16 @@ func main() {
}
}
printVals(vals, args.Simple)
if found {
printVals(vals, args.Simple)
}
}
func printVals(vals []string, simple bool) {
key := color.New(color.Bold, color.FgWhite).PrintfFunc()
value := color.New(color.FgCyan).PrintlnFunc()
keys := []string{"Protocol", "Recv-Q", "Send-Q", "Local Addr", "Remote Addr", "State", "PID/Process"}
keys := []string{"Protocol", "Recv-Q", "Send-Q", "Local Addr", "Remote Addr", "State", "PID/Process)"}
if simple {
simpleVals := []int{0,3,6}

Loading…
Cancel
Save