Exemple #1
0
func integrityVerify(filename string) bool {
	iplist := iputil.GetDetectedIpInfoSlice(filename)
	bIntegrity := true
	value := iplist[0]
	fmt.Println(value)
	for i, ipMap := range iplist {
		if i == 0 {
			continue
		}
		if ipMap["end"] == "" {
			ipMap["end"] = ipMap["ip"]
			ipMap["len"] = "1"
		}
		testip1 := iputil.InetAtonInt(value["end"])
		testip2 := iputil.InetAtonInt(ipMap["ip"])
		if isSequentail(testip1, testip2) == false {
			ip11 := iputil.InetAtonInt(value["end"]) + 1
			ip22 := iputil.InetAtonInt(ipMap["ip"]) - 1
			sip1 := iputil.InetNtoaStr(ip11)
			sip2 := iputil.InetNtoaStr(ip22)
			fmt.Println(sip1 + "|" + sip2)

			bIntegrity = false
		}
		value = ipMap
	}
	return bIntegrity
}
Exemple #2
0
func mergeAdjNetwork(filename string) {
	iplist := iputil.GetDetectedIpInfoSlice(filename)
	for i, ipMap := range iplist {
		fmt.Println(i)
		fmt.Println(ipMap)
	}
}
Exemple #3
0
func sortNetwork(filename string, sortedFile string) {
	iplist := iputil.GetDetectedIpInfoSlice(filename)
	sort.Sort(ByIP(iplist))
	resultFP, _ := os.Create(sortedFile)
	defer resultFP.Close()
	for _, v := range iplist {
		info := iputil.AllKeyinfoFormatToOutput(v) + "\n"
		resultFP.WriteString(info)
	}
}
Exemple #4
0
func MergeIP(filename, mergedFile, breakFile string) bool {
	mergeFP, err := os.Create(mergedFile)
	if err != nil {
		fmt.Println("open file failed")
		return false
	}
	defer mergeFP.Close()

	breakFP, err := os.Create(breakFile)
	if err != nil {
		fmt.Println("open file failed")
		return false
	}
	defer breakFP.Close()

	iplist := iputil.GetDetectedIpInfoSlice(filename)
	bIntegrity := true
	current := iplist[0]
	for i, ipMap := range iplist {
		if i == 0 {
			continue
		}
		if ipMap["end"] == "" {
			ipMap["end"] = ipMap["ip"]
			ipMap["len"] = "1"
		}
		testip1 := iputil.InetAtonInt(current["end"])
		testip2 := iputil.InetAtonInt(ipMap["ip"])
		if testip1 == testip2 {
			if EqualOfTwoNetwork(current, ipMap) == true {
				current = ipMap
			} else {
				fmt.Println("ERROR CURR:", current)
				fmt.Println("ERROR IPMAP:", ipMap)
			}
			current = ipMap
		} else if testip1+1 < testip2 {
			newgInfo := iputil.AllKeyinfoFormatToOutput(current)
			mergeFP.WriteString(newgInfo + "\n")
			ip11 := iputil.InetAtonInt(current["end"]) + 1
			ip22 := iputil.InetAtonInt(ipMap["ip"]) - 1
			sip1 := iputil.InetNtoaStr(ip11)
			sip2 := iputil.InetNtoaStr(ip22)
			breakFP.WriteString(sip1 + "|" + sip2 + "\n")

			bIntegrity = false
			current = ipMap
		} else if testip1+1 > testip2 {
			current = ipMap
		} else if testip1+1 == testip2 {
			if EqualOfTwoNetwork(current, ipMap) == true {
				//info1 := iputil.AllKeyinfoFormatToOutput(current)
				//info2 := iputil.AllKeyinfoFormatToOutput(ipMap)
				//fmt.Println(info1)
				//fmt.Println(info2)
				current["end"] = ipMap["end"]
				l1, _ := strconv.Atoi(current["len"])
				l2, _ := strconv.Atoi(ipMap["len"])
				current["len"] = strconv.Itoa(l1 + l2)
			} else {
				newgInfo := iputil.AllKeyinfoFormatToOutput(current)
				mergeFP.WriteString(newgInfo + "\n")
				//fmt.Println("11111 not equal start!!!")
				//fmt.Println(current)
				//fmt.Println(ipMap)
				//fmt.Println("11111 not equal end!!!")
				current = ipMap
			}
		}
	}
	return bIntegrity
}