2022-11-23 22:29:10 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2022-11-29 21:15:39 +01:00
|
|
|
func scan() []string {
|
|
|
|
var information []string
|
2022-11-23 22:29:10 +01:00
|
|
|
ifaces, _ := net.Interfaces()
|
|
|
|
for _, i := range ifaces {
|
|
|
|
addrs, _ := i.Addrs()
|
|
|
|
for _, j := range addrs {
|
|
|
|
ipv4, _, _ := net.ParseCIDR(j.String())
|
|
|
|
if ipv4.IsGlobalUnicast() && ipv4.To4() != nil {
|
|
|
|
ipv4 = ipv4.To4()
|
|
|
|
ipv4 = ipv4.Mask(ipv4.DefaultMask())
|
|
|
|
ipv4[3]++
|
|
|
|
for i := 1; i < 256; i++ {
|
|
|
|
_, dialErr := net.DialTimeout("tcp", ipv4.String()+":8081", time.Duration(1)*time.Second)
|
2022-11-29 21:15:39 +01:00
|
|
|
// _, dialErr := net.DialTimeout("tcp", "192.168.0.100:8081", time.Duration(1)*time.Second)
|
2022-11-23 22:29:10 +01:00
|
|
|
if dialErr != nil {
|
|
|
|
fmt.Println("Cannot connect to " + ipv4.String())
|
2022-11-29 21:15:39 +01:00
|
|
|
// fmt.Println("Cannot connect to " + "192.168.0.100:8081")
|
2022-11-23 22:29:10 +01:00
|
|
|
} else {
|
|
|
|
fmt.Println("Response from " + ipv4.String())
|
2022-11-29 21:15:39 +01:00
|
|
|
// fmt.Println("Response from " + "192.168.0.100:8081")
|
|
|
|
information = append(information, ipv4.String())
|
|
|
|
// information = append(information, "192.168.0.100:8081")
|
2022-11-23 22:29:10 +01:00
|
|
|
}
|
|
|
|
ipv4[3]++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return information
|
|
|
|
|
|
|
|
}
|