@@ -2,16 +2,18 @@ package zgrab2
2
2
3
3
import (
4
4
"errors"
5
+ "fmt"
5
6
"net"
6
7
"regexp"
7
8
"strconv"
8
9
"strings"
9
10
10
11
"time"
11
12
12
- "github.com/zmap/zflags"
13
- "github.com/sirupsen/logrus"
14
13
"runtime/debug"
14
+
15
+ "github.com/sirupsen/logrus"
16
+ flags "github.com/zmap/zflags"
15
17
)
16
18
17
19
var parser * flags.Parser
@@ -214,8 +216,9 @@ func IsTimeoutError(err error) bool {
214
216
// doing anything. Otherwise, it logs the stacktrace, the panic error, and the provided message
215
217
// before re-raising the original panic.
216
218
// Example:
217
- // defer zgrab2.LogPanic("Error decoding body '%x'", body)
218
- func LogPanic (format string , args ... interface {}) {
219
+ //
220
+ // defer zgrab2.LogPanic("Error decoding body '%x'", body)
221
+ func LogPanic (format string , args ... interface {}) {
219
222
err := recover ()
220
223
if err == nil {
221
224
return
@@ -224,3 +227,25 @@ func LogPanic(format string, args...interface{}) {
224
227
logrus .Errorf (format , args ... )
225
228
panic (err )
226
229
}
230
+
231
+ func AddDefaultPortToDNSServerName (inAddr string ) (string , error ) {
232
+ // Try to split host and port to see if the port is already specified.
233
+ host , port , err := net .SplitHostPort (inAddr )
234
+ if err != nil {
235
+ // might mean there's no port specified
236
+ host = inAddr
237
+ }
238
+
239
+ // Validate the host part as an IP address.
240
+ ip := net .ParseIP (host )
241
+ if ip == nil {
242
+ return "" , fmt .Errorf ("invalid IP address" )
243
+ }
244
+
245
+ // If the original input does not have a port, specify port 53
246
+ if port == "" {
247
+ port = "53"
248
+ }
249
+
250
+ return net .JoinHostPort (ip .String (), port ), nil
251
+ }
0 commit comments