Skip to content

Commit

Permalink
[ADD]add output probes to excel
Browse files Browse the repository at this point in the history
  • Loading branch information
randolphcyg committed Apr 10, 2023
1 parent ccb9913 commit 1e3ca79
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 8 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ require (
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/tealeg/xlsx v1.0.5 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
15 changes: 7 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/randolphcyg/cpe v1.0.2 h1:Ci1Ez56mtVrPPbjtU/xeZiBHi0UXbFUGtVjWcxbuF8s=
github.com/randolphcyg/cpe v1.0.2/go.mod h1:R+J264JmgNtHkgKkYS12TQNgp819+OnwFUJuZUkoyio=
github.com/randolphcyg/cpe v1.0.3 h1:Gy91SlIWvPPqIMF8gDq3tnhde6noO/AyKeeyLHp/tio=
github.com/randolphcyg/cpe v1.0.3/go.mod h1:R+J264JmgNtHkgKkYS12TQNgp819+OnwFUJuZUkoyio=
github.com/randolphcyg/cpe v1.0.4 h1:yt8reQ+oLlw4bFAcRk9t2zLGE1/11RptF0AL0XT7s2s=
github.com/randolphcyg/cpe v1.0.4/go.mod h1:R+J264JmgNtHkgKkYS12TQNgp819+OnwFUJuZUkoyio=
github.com/randolphcyg/cpe v1.0.5 h1:WNIKWlLI4uFPLRbSiuPsS8MH4QBJC+kePdTSuZ9Ppds=
github.com/randolphcyg/cpe v1.0.5/go.mod h1:R+J264JmgNtHkgKkYS12TQNgp819+OnwFUJuZUkoyio=
github.com/randolphcyg/cpe v1.0.6 h1:6/jVTznDzniah986/31eGAy+STpkObmeSZ2wEQrtKP0=
github.com/randolphcyg/cpe v1.0.6/go.mod h1:R+J264JmgNtHkgKkYS12TQNgp819+OnwFUJuZUkoyio=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand All @@ -22,8 +17,12 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/tealeg/xlsx v1.0.5 h1:+f8oFmvY8Gw1iUXzPk+kz+4GpbDZPK1FhPiQRd+ypgE=
github.com/tealeg/xlsx v1.0.5/go.mod h1:btRS8dz54TDnvKNosuAqxrM1QgN1udgk9O34bDCnORM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
77 changes: 77 additions & 0 deletions tests/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/tealeg/xlsx"

"github.com/randolphcyg/nmap-parser"
)
Expand Down Expand Up @@ -126,3 +127,79 @@ func TestParseMatchVInfoFieldOutOfOrder(t *testing.T) {
match, _ := parser.ParseMatch(str)
assert.Equal(t, "Windows", match.VersionInfo.OperatingSystem)
}

// TestOutToExcel output probes to excel
func TestOutToExcel(t *testing.T) {
file := xlsx.NewFile()
sheet, err := file.AddSheet("nmap-probe-support-service")
if err != nil {
panic(err)
}

srcFilePath := "nmap-service-probes"
probes, err := parser.ParseNmapServiceProbe(srcFilePath)
if err != nil {
panic(err)
}

sheetRowHeader := sheet.AddRow()
sheetRowHeader.SetHeightCM(2) // 设置行高

sheetCellHeader1 := sheetRowHeader.AddCell()
sheetCellHeader1.Value = "服务名"

sheetCellHeader2 := sheetRowHeader.AddCell()
sheetCellHeader2.Value = "版本"

sheetCellHeader3 := sheetRowHeader.AddCell()
sheetCellHeader3.Value = "运行设备类型"

sheetCellHeader4 := sheetRowHeader.AddCell()
sheetCellHeader4.Value = "供应商和服务名称"

sheetCellHeader5 := sheetRowHeader.AddCell()
sheetCellHeader5.Value = "更多信息"

sheetCellHeader6 := sheetRowHeader.AddCell()
sheetCellHeader6.Value = "服务提供的主机名"

sheetCellHeader7 := sheetRowHeader.AddCell()
sheetCellHeader7.Value = "CPE"

for _, probe := range probes {
for _, service := range probe.Matches {

sheetRow := sheet.AddRow()
sheetRow.SetHeightCM(1) // 设置行高

sheetCell1 := sheetRow.AddCell()
sheetCell1.Value = service.Name

sheetCell2 := sheetRow.AddCell()
sheetCell2.Value = service.VersionInfo.Version

sheetCell3 := sheetRow.AddCell()
sheetCell3.Value = service.VersionInfo.DeviceType

sheetCell4 := sheetRow.AddCell()
sheetCell4.Value = service.VersionInfo.VendorProductName

sheetCell5 := sheetRow.AddCell()
sheetCell5.Value = service.VersionInfo.Info

sheetCell6 := sheetRow.AddCell()
sheetCell6.Value = service.VersionInfo.Hostname

sheetCell7 := sheetRow.AddCell()
marshal, _ := json.Marshal(service.VersionInfo.Cpe)

sheetCell7.Value = string(marshal)

}
}

err = file.Save("nmap-probe-support-service.xlsx")
if err != nil {
panic(err)
}
}

0 comments on commit 1e3ca79

Please sign in to comment.