Skip to content

Commit

Permalink
Removed colors when running on Windows and fixed IP address parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
nullt3r committed Nov 17, 2022
1 parent 968464b commit dcf1afc
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 20 deletions.
12 changes: 6 additions & 6 deletions cmd/udpx/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,23 @@ func main() {
/ / / / / / / /_/ / /
/ /_/ / /_/ / ____/ |
\____/_____/_/ /_/|_|
v1.0.0-beta, by @nullt3r
v1.0.2-beta, by @nullt3r
%s`, utils.ColorCyan, utils.ColorReset)
%s`, utils.SetColor().Cyan, utils.SetColor().Reset)

opts := utils.ParseOptions()

var targets []string
var ips []string

if len(opts.Arg_t) == 0 && len(opts.Arg_tf) == 0 {
log.Fatalf("%s[!]%s Error, argument -t or -tf is required\n", utils.ColorRed, utils.ColorReset)
log.Fatalf("%s[!]%s Error, argument -t or -tf is required\n", utils.SetColor().Red, utils.SetColor().Reset)
}

if len(opts.Arg_tf) != 0 {
val, err := utils.ReadFile(opts.Arg_tf)
if err != nil {
log.Fatalf("%s[!]%s Error while loading targets from file: %s", utils.ColorRed, utils.ColorReset, err)
log.Fatalf("%s[!]%s Error while loading targets from file: %s", utils.SetColor().Red, utils.SetColor().Reset, err)
}
targets = val
} else if len(opts.Arg_t) != 0 {
Expand All @@ -48,7 +48,7 @@ func main() {
val, err := utils.IpsFromCidr(target)

if err != nil {
log.Fatalf("%s[!]%s Error parsing IP range: %s", utils.ColorRed, utils.ColorReset, err)
log.Fatalf("%s[!]%s Error parsing IP range: %s", utils.SetColor().Red, utils.SetColor().Reset, err)
}

ips = append(ips, val...)
Expand All @@ -64,7 +64,7 @@ func main() {
break
}
if n == len(probes.Probes)-1 {
log.Fatalf("%s[!]%s Service '%s' is not supported", utils.ColorRed, utils.ColorReset, opts.Arg_s)
log.Fatalf("%s[!]%s Service '%s' is not supported", utils.SetColor().Red, utils.SetColor().Reset, opts.Arg_s)
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/scan/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (s Scanner) Run() {
c, err := net.Dial("udp", fmt.Sprint(s.Ip, ":", probe.Port))

if err != nil {
log.Printf("%s[!]%s [%s] Error connecting to host '%s': %s", utils.ColorRed, utils.ColorReset, probe.Name, s.Ip, err)
log.Printf("%s[!]%s [%s] Error connecting to host '%s': %s", utils.SetColor().Red, utils.SetColor().Reset, probe.Name, s.Ip, err)
return
}

Expand All @@ -45,7 +45,7 @@ func (s Scanner) Run() {
Data, err := hex.DecodeString(probe.Data)

if err != nil {
log.Fatalf("%s[!]%s Error in decoding probe data. Problem probe: '%s'", utils.ColorRed, utils.ColorReset, probe.Name)
log.Fatalf("%s[!]%s Error in decoding probe data. Problem probe: '%s'", utils.SetColor().Red, utils.SetColor().Reset, probe.Name)
}

_, err = c.Write([]byte(Data))
Expand All @@ -63,9 +63,9 @@ func (s Scanner) Run() {
}

if recv_length != 0 {
log.Printf("%s[*]%s %s:%d (%s)", utils.ColorCyan, utils.ColorReset, s.Ip, probe.Port, probe.Name)
log.Printf("%s[*]%s %s:%d (%s)", utils.SetColor().Cyan, utils.SetColor().Reset, s.Ip, probe.Port, probe.Name)
if s.Arg_sp {
log.Printf("[+] Received packet: %s%s%s...", utils.ColorYellow, hex.EncodeToString(recv_Data), utils.ColorReset)
log.Printf("[+] Received packet: %s%s%s...", utils.SetColor().Yellow, hex.EncodeToString(recv_Data), utils.SetColor().Reset)
}
s.Result <- fmt.Sprintf("%s:%d %s", s.Ip, probe.Port, probe.Name)
}
Expand Down
33 changes: 27 additions & 6 deletions pkg/utils/color_output.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,29 @@
package utils

const (
ColorCyan = "\033[36m"
ColorYellow = "\033[33m"
ColorRed = "\033[1;31m"
ColorReset = "\033[0m"
)
import "runtime"

type colors struct {
Cyan string
Yellow string
Red string
Reset string
}

func SetColor() *colors {
c := &colors{}

if runtime.GOOS == "windows" {
c.Cyan = ""
c.Yellow = ""
c.Red = ""
c.Reset = ""
} else {
c.Cyan = "\033[36m"
c.Yellow = "\033[33m"
c.Red = "\033[1;31m"
c.Reset = "\033[0m"
}

return c

}
10 changes: 6 additions & 4 deletions pkg/utils/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ func IpsFromCidr(cidr string) ([]string, error) {
}

// If mask is /32 or /31
if len(ips) <= 2 {
return ips, nil
}
//if len(ips) <= 2 {
// return ips, nil
//}

// remove network address and broadcast address
return ips[1 : len(ips)-1], nil
//return ips[1 : len(ips)-1], nil

return ips, nil
}

func ReadFile(path string) ([]string, error) {
Expand Down
Binary file added udpx
Binary file not shown.

0 comments on commit dcf1afc

Please sign in to comment.