From 33afcca22e439765e4399459fff3d836979cfce5 Mon Sep 17 00:00:00 2001 From: Volodymyr Komarov Date: Sun, 8 Mar 2020 18:23:02 +0200 Subject: [PATCH 01/11] Add first test. Integrate TravisCI --- .gitignore | 1 + .travis.yml | 31 +++++++++++++++++++++++++++ scanner/host/host_test.go | 45 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 .travis.yml create mode 100644 scanner/host/host_test.go diff --git a/.gitignore b/.gitignore index 9808852..7ce1bf9 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ *.so *.dylib .idea +coverage.out # Test binary, built with `go test -c` *.test diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..af06b9a --- /dev/null +++ b/.travis.yml @@ -0,0 +1,31 @@ +language: go + +go: + - '1.14' + +install: + - go get golang.org/x/tools/cmd/cover + - go get github.com/mattn/goveralls + - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.23.6 + +script: + - go test ./... -v -covermode=count -coverprofile=coverage.out + - cat coverage.out | grep -v "main.go" | grep -v "hosts.go" | grep -v "ports.go" > cover.out + - goveralls -coverprofile=cover.out -service=travis-ci + - golangci-lint run + + - CGO_ENABLED=0 GOARCH=386 GOOS=linux go build -o out/netshark_linux_i686 . + - CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -o out/netshark_linux_x86-64 . + - GOARCH=amd64 GOOS=darwin go build -o out/netshark_osx . + - GOARCH=386 GOOS=windows go build -o out/netshark_win32.exe . + - GOARCH=amd64 GOOS=windows go build -o out/netshark_win64.exe . + +deploy: + provider: releases + api_key: + secure: $GITHUB_API_KEY_SECURE + file_glob: true + file: out/* + skip_cleanup: true + on: + tags: true diff --git a/scanner/host/host_test.go b/scanner/host/host_test.go new file mode 100644 index 0000000..852f902 --- /dev/null +++ b/scanner/host/host_test.go @@ -0,0 +1,45 @@ +package host + +import "testing" + +func TestHost_ID(t *testing.T) { + for _, test := range []struct { + IP string + MAC string + ID string + }{ + { + ID: "d41d8cd98f00b204e9800998ecf8427e", + }, + { + IP: "192.168.1.1", + ID: "66efff4c945d3c3b87fc271b47d456db", + }, + { + MAC: "28:6c:07:48:66:be", + ID: "924a7370c8df57b5b3f0a2e0d9d91598", + }, + { + IP: "192.168.1.1", + MAC: "28:6c:07:48:66:be", + ID: "7a48a7ba6494c7eb4c06e4787e9a6a88", + }, + } { + host := Host{ + IP: test.IP, + MAC: test.MAC, + } + + if host.id != "" { + t.Errorf("initial Host ID is not empty") + } + + if host.ID() != test.ID { + t.Errorf("test Host ID [%s] is not equal to actual Host ID [%s]", test.ID, host.ID()) + } + + if host.id == "" { + t.Errorf("Host ID is not cached") + } + } +} From 7ae151219a7b9e1471997d68b8b55d2c6f8322aa Mon Sep 17 00:00:00 2001 From: Volodymyr Komarov Date: Sun, 8 Mar 2020 18:33:04 +0200 Subject: [PATCH 02/11] Fix failing build for clear environment without pcap library --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index af06b9a..b0eb533 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,9 @@ language: go go: - '1.14' +before_install: + - sudo apt-get install libpcap-dev + install: - go get golang.org/x/tools/cmd/cover - go get github.com/mattn/goveralls From 79355c4ec96156008e66104c20c3e0a8efc53eb2 Mon Sep 17 00:00:00 2001 From: Volodymyr Komarov Date: Sun, 8 Mar 2020 19:09:03 +0200 Subject: [PATCH 03/11] Building pcap before build end tool --- .travis.yml | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index b0eb533..4c3888c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,9 +17,24 @@ script: - goveralls -coverprofile=cover.out -service=travis-ci - golangci-lint run - - CGO_ENABLED=0 GOARCH=386 GOOS=linux go build -o out/netshark_linux_i686 . - - CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -o out/netshark_linux_x86-64 . - - GOARCH=amd64 GOOS=darwin go build -o out/netshark_osx . + - export PCAPV=1.9.1 + - wget http://www.tcpdump.org/release/libpcap-$PCAPV.tar.gz && \ + tar xvf libpcap-$PCAPV.tar.gz && \ + cd libpcap-$PCAPV && \ + ./configure --with-pcap=linux && \ + make && \ + cd .. + + - CGO_ENABLED=0 GOARCH=386 GOOS=linux go build --ldflags "-L ./libpcap-$PCAPV -linkmode external -extldflags \"-static\"" -a -o out/netshark_linux_i686 . + - CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build --ldflags "-L ./libpcap-$PCAPV -linkmode external -extldflags \"-static\"" -a -o out/netshark_linux_x86-64 . + + - cd libpcap-$PCAPV && \ + ./configure --with-pcap=linux && \ + make && \ + cd .. + + - GOARCH=amd64 GOOS=darwin go build --ldflags "-L ./libpcap-$PCAPV -linkmode external -extldflags \"-static\"" -a -o out/netshark_osx . + - GOARCH=386 GOOS=windows go build -o out/netshark_win32.exe . - GOARCH=amd64 GOOS=windows go build -o out/netshark_win64.exe . From 37c046599ea66a8e0a18e1cb6384996ab7d8d937 Mon Sep 17 00:00:00 2001 From: Volodymyr Komarov Date: Sun, 8 Mar 2020 19:11:17 +0200 Subject: [PATCH 04/11] Install tar to unpack sources --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 4c3888c..b6259cf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ go: - '1.14' before_install: - - sudo apt-get install libpcap-dev + - sudo apt-get install libpcap-dev tag install: - go get golang.org/x/tools/cmd/cover From 2019c1ec081e528af2fa9b45c8743175ab332bf2 Mon Sep 17 00:00:00 2001 From: Volodymyr Komarov Date: Sun, 8 Mar 2020 19:14:27 +0200 Subject: [PATCH 05/11] Install tar to unpack sources --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index b6259cf..5a30acf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ go: - '1.14' before_install: - - sudo apt-get install libpcap-dev tag + - sudo apt-get install libpcap-dev tar install: - go get golang.org/x/tools/cmd/cover From c898a541fd1034aacf637ef165b418c84bdece49 Mon Sep 17 00:00:00 2001 From: Volodymyr Komarov Date: Sun, 8 Mar 2020 19:20:50 +0200 Subject: [PATCH 06/11] Update pcap build script --- .travis.yml | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5a30acf..af2f128 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,20 +18,21 @@ script: - golangci-lint run - export PCAPV=1.9.1 - - wget http://www.tcpdump.org/release/libpcap-$PCAPV.tar.gz && \ - tar xvf libpcap-$PCAPV.tar.gz && \ - cd libpcap-$PCAPV && \ - ./configure --with-pcap=linux && \ - make && \ - cd .. + - wget http://www.tcpdump.org/release/libpcap-$PCAPV.tar.gz + - tar xvf libpcap-$PCAPV.tar.gz + + - cd libpcap-$PCAPV + - ./configure --with-pcap=linux + - make + - cd .. - CGO_ENABLED=0 GOARCH=386 GOOS=linux go build --ldflags "-L ./libpcap-$PCAPV -linkmode external -extldflags \"-static\"" -a -o out/netshark_linux_i686 . - CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build --ldflags "-L ./libpcap-$PCAPV -linkmode external -extldflags \"-static\"" -a -o out/netshark_linux_x86-64 . - - cd libpcap-$PCAPV && \ - ./configure --with-pcap=linux && \ - make && \ - cd .. + - cd libpcap-$PCAPV + - ./configure --with-pcap=bpf + - make + - cd .. - GOARCH=amd64 GOOS=darwin go build --ldflags "-L ./libpcap-$PCAPV -linkmode external -extldflags \"-static\"" -a -o out/netshark_osx . From 29369b57dcfe3c91cbb4b8fab0ea645baa05c0e1 Mon Sep 17 00:00:00 2001 From: Volodymyr Komarov Date: Sun, 8 Mar 2020 19:45:10 +0200 Subject: [PATCH 07/11] Update pcap build script #2 --- .travis.yml | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index af2f128..82d4c22 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,13 +26,8 @@ script: - make - cd .. - - CGO_ENABLED=0 GOARCH=386 GOOS=linux go build --ldflags "-L ./libpcap-$PCAPV -linkmode external -extldflags \"-static\"" -a -o out/netshark_linux_i686 . - - CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build --ldflags "-L ./libpcap-$PCAPV -linkmode external -extldflags \"-static\"" -a -o out/netshark_linux_x86-64 . - - - cd libpcap-$PCAPV - - ./configure --with-pcap=bpf - - make - - cd .. + - CGO_ENABLED=0 GOARCH=386 GOOS=linux CGO_LDFLAGS+="-L./libpcap-$PCAPV" go build -ldflags="-s -w" -o out/netshark_linux_i686 . + - CGO_ENABLED=0 GOARCH=amd64 GOOS=linux CGO_LDFLAGS+="-L./libpcap-$PCAPV" go build -ldflags="-s -w" -o out/netshark_linux_x86-64 . - GOARCH=amd64 GOOS=darwin go build --ldflags "-L ./libpcap-$PCAPV -linkmode external -extldflags \"-static\"" -a -o out/netshark_osx . From 2b5ea1903802a6bb62bb2fe7c3e2a20560be45bb Mon Sep 17 00:00:00 2001 From: Volodymyr Komarov Date: Sun, 8 Mar 2020 19:48:16 +0200 Subject: [PATCH 08/11] Update pcap build script #3 --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 82d4c22..bd7d562 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ go: - '1.14' before_install: - - sudo apt-get install libpcap-dev tar + - sudo apt-get install libpcap-dev install: - go get golang.org/x/tools/cmd/cover @@ -26,8 +26,8 @@ script: - make - cd .. - - CGO_ENABLED=0 GOARCH=386 GOOS=linux CGO_LDFLAGS+="-L./libpcap-$PCAPV" go build -ldflags="-s -w" -o out/netshark_linux_i686 . - - CGO_ENABLED=0 GOARCH=amd64 GOOS=linux CGO_LDFLAGS+="-L./libpcap-$PCAPV" go build -ldflags="-s -w" -o out/netshark_linux_x86-64 . + - CGO_ENABLED=1 GOARCH=386 GOOS=linux CGO_LDFLAGS+="-L./libpcap-$PCAPV" go build -ldflags="-s -w" -o out/netshark_linux_i686 . + - CGO_ENABLED=1 GOARCH=amd64 GOOS=linux CGO_LDFLAGS+="-L./libpcap-$PCAPV" go build -ldflags="-s -w" -o out/netshark_linux_x86-64 . - GOARCH=amd64 GOOS=darwin go build --ldflags "-L ./libpcap-$PCAPV -linkmode external -extldflags \"-static\"" -a -o out/netshark_osx . From 9b7078134cde946b1aae127ee3d27779f1c2605e Mon Sep 17 00:00:00 2001 From: Volodymyr Komarov Date: Sun, 8 Mar 2020 19:52:13 +0200 Subject: [PATCH 09/11] Update pcap build script #4 --- .travis.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index bd7d562..64b20e1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,10 +26,9 @@ script: - make - cd .. - - CGO_ENABLED=1 GOARCH=386 GOOS=linux CGO_LDFLAGS+="-L./libpcap-$PCAPV" go build -ldflags="-s -w" -o out/netshark_linux_i686 . - CGO_ENABLED=1 GOARCH=amd64 GOOS=linux CGO_LDFLAGS+="-L./libpcap-$PCAPV" go build -ldflags="-s -w" -o out/netshark_linux_x86-64 . - - - GOARCH=amd64 GOOS=darwin go build --ldflags "-L ./libpcap-$PCAPV -linkmode external -extldflags \"-static\"" -a -o out/netshark_osx . + - CGO_ENABLED=1 GOARCH=amd64 GOOS=darwin CGO_LDFLAGS+="-L./libpcap-$PCAPV" go build -ldflags="-s -w" -o out/netshark_osx . +# - CGO_ENABLED=1 GOARCH=amd64 GOOS=darwin go build --ldflags "-L ./libpcap-$PCAPV -linkmode external -extldflags \"-static\"" -a -o out/netshark_osx . - GOARCH=386 GOOS=windows go build -o out/netshark_win32.exe . - GOARCH=amd64 GOOS=windows go build -o out/netshark_win64.exe . From 6fd7d9e1b5891ea3160cd008022431664e7dbffd Mon Sep 17 00:00:00 2001 From: Volodymyr Komarov Date: Sun, 8 Mar 2020 20:04:11 +0200 Subject: [PATCH 10/11] Update pcap build script #5 --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 64b20e1..d9b54d6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,8 +27,8 @@ script: - cd .. - CGO_ENABLED=1 GOARCH=amd64 GOOS=linux CGO_LDFLAGS+="-L./libpcap-$PCAPV" go build -ldflags="-s -w" -o out/netshark_linux_x86-64 . - - CGO_ENABLED=1 GOARCH=amd64 GOOS=darwin CGO_LDFLAGS+="-L./libpcap-$PCAPV" go build -ldflags="-s -w" -o out/netshark_osx . -# - CGO_ENABLED=1 GOARCH=amd64 GOOS=darwin go build --ldflags "-L ./libpcap-$PCAPV -linkmode external -extldflags \"-static\"" -a -o out/netshark_osx . +# - CGO_ENABLED=1 GOARCH=amd64 GOOS=darwin CGO_LDFLAGS+="-L./libpcap-$PCAPV" go build -ldflags="-s -w" -o out/netshark_osx . + - CGO_ENABLED=0 GOARCH=amd64 GOOS=darwin go build --ldflags "-L ./libpcap-$PCAPV -linkmode external -extldflags \"-static\"" -a -o out/netshark_osx . - GOARCH=386 GOOS=windows go build -o out/netshark_win32.exe . - GOARCH=amd64 GOOS=windows go build -o out/netshark_win64.exe . From d5e4bb66b9fea7afeb9c8d6315b015daa31af4f7 Mon Sep 17 00:00:00 2001 From: Volodymyr Komarov Date: Sun, 8 Mar 2020 20:07:56 +0200 Subject: [PATCH 11/11] Fix cross compilation --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index d9b54d6..1ab3cc8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,15 +20,15 @@ script: - export PCAPV=1.9.1 - wget http://www.tcpdump.org/release/libpcap-$PCAPV.tar.gz - tar xvf libpcap-$PCAPV.tar.gz - - cd libpcap-$PCAPV - ./configure --with-pcap=linux - make - cd .. - CGO_ENABLED=1 GOARCH=amd64 GOOS=linux CGO_LDFLAGS+="-L./libpcap-$PCAPV" go build -ldflags="-s -w" -o out/netshark_linux_x86-64 . -# - CGO_ENABLED=1 GOARCH=amd64 GOOS=darwin CGO_LDFLAGS+="-L./libpcap-$PCAPV" go build -ldflags="-s -w" -o out/netshark_osx . - - CGO_ENABLED=0 GOARCH=amd64 GOOS=darwin go build --ldflags "-L ./libpcap-$PCAPV -linkmode external -extldflags \"-static\"" -a -o out/netshark_osx . + + # TODO. MacOS build + # - GOARCH=amd64 GOOS=darwin go build -o out/netshark_osx . - GOARCH=386 GOOS=windows go build -o out/netshark_win32.exe . - GOARCH=amd64 GOOS=windows go build -o out/netshark_win64.exe .