@@ -12,6 +12,7 @@ import (
12
12
"strings"
13
13
//"syscall"
14
14
"time"
15
+ "syscall"
15
16
16
17
portscanner "github.com/anvie/port-scanner"
17
18
"github.com/jackpal/gateway"
@@ -229,8 +230,29 @@ func PortscanSingle(target string, port int) bool {
229
230
return len (opened_ports ) != 0
230
231
}
231
232
233
+ // Returns true if host is alive
234
+ func Ping (target string ) bool {
235
+ open_counter := 0
236
+ ports_to_check := []int {80 , 443 , 21 , 22 }
237
+ ps := portscanner .NewPortScanner (target , 2 * time .Second , 5 )
238
+ for _ , port := range ports_to_check {
239
+ if ps .IsOpen (port ){
240
+ open_counter += 1
241
+ }
242
+ }
243
+ return true
244
+ }
245
+
246
+ // Removes hosts from slice that did not respond to a ping request
247
+ func RemoveInactive (targets []string ) {
248
+ for i , t := range (targets ){
249
+ if ! Ping (t ){
250
+ targets [i ] = ""
251
+ }
252
+ }
253
+ }
232
254
233
- //PortFree returns a random free port
255
+ // Returns a random free port
234
256
func PortFree (port int ) int {
235
257
var a * net.TCPAddr
236
258
a , err := net .ResolveTCPAddr ("tcp" , "localhost:0" )
@@ -243,8 +265,14 @@ func PortFree(port int) int {
243
265
return l .Addr ().(* net.TCPAddr ).Port
244
266
}
245
267
246
- // TargetProcessor returns a sorted list of targets based on their RRT pingback value
247
- //func TargetProcessor(targets []string) []string {
248
-
249
- //}
268
+ func PortReuse (network string , address string , conn syscall.RawConn ) error {
269
+ return portReuse (network , address , conn )
270
+ }
250
271
272
+ // Gracefully closes an instance of net.Listener
273
+ func CloseListener (lst net.Listener ){
274
+ if lst != nil {
275
+ lst .Close ()
276
+ lst = nil
277
+ }
278
+ }
0 commit comments