Last active
September 26, 2020 06:39
-
-
Save yehgdotnet/1307019cb8af5e1e8ab6baae4e5f569b to your computer and use it in GitHub Desktop.
recordlookup.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bufio" | |
"fmt" | |
"log" | |
"os" | |
"strings" | |
"regexp" | |
) | |
var ( | |
path_ip = "ips.txt" | |
path_record = "records.txt" | |
) | |
func find_in_records(needle string,full_line string){ | |
file, err := os.Open(path_record) | |
if err != nil { | |
log.Fatal(err) | |
} | |
defer file.Close() | |
scanner := bufio.NewScanner(file) | |
for scanner.Scan() { | |
line:= scanner.Text() | |
if strings.Contains(line,needle) { | |
result_line := line + full_line | |
result_line = strings.Replace(result_line,needle,"",2) | |
result_line = strings.Replace(result_line,"Ports:","",2) | |
fmt.Println(result_line + "\n\n") | |
break | |
}else{ | |
//fmt.Println("not match: " + needle + " at line: " +line) | |
} | |
} | |
if err := scanner.Err(); err != nil { | |
log.Fatal(err) | |
} | |
} | |
func execute_find() { | |
file, err := os.Open(path_ip ) | |
if err != nil { | |
log.Fatal(err) | |
} | |
defer file.Close() | |
scanner := bufio.NewScanner(file) | |
re := regexp.MustCompile(`(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}`) | |
for scanner.Scan() { | |
line:= scanner.Text() | |
submatchall := re.FindAllString(line, -1) | |
if re.MatchString(line){ | |
each_ip := submatchall[0] | |
find_in_records(each_ip,line) | |
} | |
} | |
if err := scanner.Err(); err != nil { | |
log.Fatal(err) | |
} | |
} | |
func main(){ | |
execute_find() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment