update icmp threads

This commit is contained in:
shadow1ng
2020-11-16 19:55:00 +08:00
parent f8285de94d
commit 468c2a0ff9
5 changed files with 45 additions and 24 deletions
+12 -14
View File
@@ -71,7 +71,7 @@ func isping(ip string) bool {
buffer.Reset()
binary.Write(&buffer, binary.BigEndian, icmp)
Time, _ := time.ParseDuration("2s")
Time, _ := time.ParseDuration("3s")
conn, err := net.DialTimeout("ip4:icmp", ip, Time)
if err != nil {
return false
@@ -80,7 +80,7 @@ func isping(ip string) bool {
if err != nil {
return false
}
conn.SetReadDeadline(time.Now().Add(time.Second * 2))
conn.SetReadDeadline(time.Now().Add(time.Second * 3))
num, err := conn.Read(recvBuf)
if err != nil {
return false
@@ -115,11 +115,13 @@ func CheckSum(data []byte) uint16 {
return uint16(^sum)
}
func IcmpCheck(hostslist []string) {
func IcmpCheck(hostslist []string,IcmpThreads int) {
var wg sync.WaitGroup
mutex := &sync.Mutex{}
limiter := make(chan int, IcmpThreads)
for _,host :=range hostslist{
wg.Add(1)
limiter <- 1
go func(host string) {
defer wg.Done()
if isping(host){
@@ -127,11 +129,14 @@ func IcmpCheck(hostslist []string) {
AliveHosts = append(AliveHosts, host)
mutex.Unlock()
}
<- limiter
}(host)
}
wg.Wait()
}
func ExecCommandPing(ip string,bsenv string) bool {
command := exec.Command(bsenv, "-c", "ping -c 1 -w 1 "+ip+" >/dev/null && echo true || echo false") //ping -c 1 -i 0.5 -t 4 -W 2 -w 5 "+ip+" >/dev/null && echo true || echo false"
outinfo := bytes.Buffer{}
@@ -156,12 +161,6 @@ func PingCMDcheck(hostslist []string,bsenv string) {
var wg sync.WaitGroup
mutex := &sync.Mutex{}
limiter := make(chan struct{}, 40)
//aliveHost := make(chan string, 20)
//go func() {
// for s := range aliveHost {
// fmt.Println(s)
// }
//}()
for _,host :=range hostslist{
wg.Add(1)
limiter <- struct{}{}
@@ -177,24 +176,23 @@ func PingCMDcheck(hostslist []string,bsenv string) {
}(host)
}
wg.Wait()
//close(aliveHost)
}
func ICMPRun(hostslist []string) []string{
func ICMPRun(hostslist []string,IcmpThreads int) []string{
var sysinfo SystemInfo
sysinfo = GetSys()
if sysinfo.OS == "windows" {
IcmpCheck(hostslist)
IcmpCheck(hostslist,IcmpThreads)
}else if sysinfo.OS == "linux" {
if (sysinfo.Groupid == "0" || sysinfo.Userid == "0" || sysinfo.Username == "root") {
IcmpCheck(hostslist)
IcmpCheck(hostslist,IcmpThreads)
}else {
PingCMDcheck(hostslist,"/bin/bash")
}
}else if sysinfo.OS == "darwin" {
if (sysinfo.Groupid == "0" || sysinfo.Userid == "0" || sysinfo.Username == "root") {
IcmpCheck(hostslist)
IcmpCheck(hostslist,IcmpThreads)
}else {
PingCMDcheck(hostslist,"/usr/local/bin/bash")
}
+8 -6
View File
@@ -81,7 +81,7 @@ func Expoilt(info *common.HostInfo,realhost string,conn net.Conn) {
result := fmt.Sprintf("%v SSH public key was written successfully",realhost)
common.LogSuccess(result)
}else {
fmt.Println(realhost,"SSHPUB write failed",text)
fmt.Println("Redis:",realhost,"SSHPUB write failed",text)
}
}
}
@@ -94,7 +94,7 @@ func Expoilt(info *common.HostInfo,realhost string,conn net.Conn) {
result := fmt.Sprintf("%v /var/spool/cron/root was written successfully",realhost)
common.LogSuccess(result)
}else {
fmt.Println(realhost,"cron write failed",text)
fmt.Println("Redis:",realhost,"cron write failed",text)
}
}
}
@@ -121,6 +121,7 @@ func writekey(conn net.Conn,filename string) (flag bool,text string) {
}
}
}
text = strings.TrimSpace(text)
if len(text) > 50{
text = text[:50]
}
@@ -145,10 +146,11 @@ func writecron(conn net.Conn,host string) (flag bool,text string) {
text,_ = readreply(conn)
if strings.Contains(text,"OK") {
flag = true
}
}
}
}
}//else {fmt.Println(text)}
}//else {fmt.Println(text)}
}//else {fmt.Println(text)}
}//else {fmt.Println(text)}
text = strings.TrimSpace(text)
if len(text) > 50{
text = text[:50]
}
+3 -2
View File
@@ -34,9 +34,10 @@ func IsContain(items []string, item string) bool {
}
func Scan(info common.HostInfo) {
fmt.Println("scan start")
Hosts,_ := common.ParseIP(info.Host,info.HostFile)
if info.Isping == false{
Hosts = ICMPRun(Hosts)
Hosts = ICMPRun(Hosts,info.IcmpThreads)
}
_,AlivePorts := TCPportScan(Hosts,info.Ports,"icmp",3) //return AliveHosts,AlivePorts
var severports []string //severports := []string{"21","22","135"."445","1433","3306","5432","6379","9200","11211","27017"...}
@@ -64,7 +65,7 @@ func Scan(info common.HostInfo) {
AddScan("1000002",info,ch,&wg)
}
}else {
port,_:=common.PORTList[info.Scantype]
port,_:=common.PORTList_bak[info.Scantype]
scantype = strconv.Itoa(port)
AddScan(scantype,info,ch,&wg)
}