From 88c07d5077a0a77891bf013c859e2374140a721b Mon Sep 17 00:00:00 2001 From: Carl <631929063@qq.com> Date: Tue, 27 Sep 2022 14:24:52 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9B=B4=E6=8E=A5=E4=BD=BF=E7=94=A8=E5=AD=90?= =?UTF-8?q?=E5=88=87=E7=89=87=E5=AF=BC=E8=87=B4=E7=9A=84=E5=86=85=E5=AD=98?= =?UTF-8?q?=E6=B3=84=E6=BC=8F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- netstat.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/netstat.go b/netstat.go index 35037df..81d870e 100644 --- a/netstat.go +++ b/netstat.go @@ -1,6 +1,7 @@ package netflow import ( + "bytes" "fmt" "io/ioutil" "os" @@ -65,8 +66,16 @@ func parseNetworkLines(tp string) ([]string, error) { return nil, err } - lines := strings.Split(string(data), "\n") - return lines[1 : len(lines)-1], nil + lines := bytes.Split(data, []byte("\n")) + var netString []string + fileLens := len(lines) + for i, line := range lines { + if i == 0 || i == fileLens-1 { + continue + } + netString = append(netString, string(line)) + } + return netString, nil } func hex2dec(hexstr string) string {