Skip to content
This repository has been archived by the owner on Jan 13, 2023. It is now read-only.

Support for specified range ports #161

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions core/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,32 @@ func (s *Session) initPorts() {
for _, p := range strings.Split(*s.Options.Ports, ",") {
port, err := strconv.Atoi(strings.TrimSpace(p))
if err != nil {
ranges := strings.Split(p, "-")

if len(ranges) > 1 {
start_port, err := strconv.Atoi(strings.TrimSpace(ranges[0]))
if err != nil {
s.Out.Fatal("[start port] Invalid port range given")
os.Exit(1)
}

end_port, err := strconv.Atoi(strings.TrimSpace(ranges[1]))
if err != nil {
s.Out.Fatal("[end port] Invalid port range given")
os.Exit(1)
}

for i:= start_port; i <= end_port; i++ {
if i < 1 || i > 65535 {
s.Out.Fatal("Invalid port give: %v\n", i)
os.Exit(1)
}
ports = append(ports, i)
}

continue
}

s.Out.Fatal("Invalid port range given\n")
os.Exit(1)
}
Expand Down