-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
first version 🚀
- Loading branch information
0 parents
commit e4041ed
Showing
12 changed files
with
353 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module ipmap | ||
|
||
go 1.19 | ||
|
||
require github.com/corpix/uarand v0.2.0 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
github.com/corpix/uarand v0.2.0 h1:U98xXwud/AVuCpkpgfPF7J5TQgr7R5tqT8VZP5KWbzE= | ||
github.com/corpix/uarand v0.2.0/go.mod h1:/3Z1QIqWkDIhf6XWn/08/uMHoQ8JUoTIKc2iPchBOmM= | ||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= | ||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY= | ||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"ipmap/modules" | ||
"ipmap/tools" | ||
"strconv" | ||
"strings" | ||
) | ||
|
||
var ( | ||
domain = flag.String("d", "", "domain parameter") | ||
asn = flag.String("asn", "", "asn parameter") | ||
ip = flag.String("ip", "", "ip parameter") | ||
timeout = flag.Int("t", 0, "timeout parameter") | ||
con = flag.Bool("c", false, "continue parameter") | ||
export = flag.Bool("export", false, "export parameter") | ||
DomainTitle string | ||
) | ||
|
||
func main() { | ||
flag.Parse() | ||
if (*asn != "" && *ip != "") || (*asn == "" && *ip == "") { | ||
fmt.Println("======================================================\n" + | ||
" ipmap v1.0 (github.com/sercanarga/ipmap)\n" + | ||
"======================================================\n" + | ||
"PARAMETERS:\n" + | ||
"-asn AS13335\n" + | ||
"-ip 103.21.244.0/22,103.22.200.0/22\n" + | ||
"-d example.com\n" + | ||
"-t 200 (timout default:auto)\n" + | ||
"--c (work until finish scanning)\n" + | ||
"--export (auto export results)\n\n" + | ||
"USAGES:\n" + | ||
"Finding sites by scanning all the IP blocks\nipmap -ip 103.21.244.0/22,103.22.200.0/22\n\n" + | ||
"Finding real IP address of site by scanning given IP addresses\nipmap -ip 103.21.244.0/22,103.22.200.0/22 -d example.com\n\n" + | ||
"Finding sites by scanning all the IP blocks in the ASN\nipmap -asn AS13335\n\n" + | ||
"Finding real IP address of site by scanning all IP blocks in ASN\nipmap -asn AS13335 -d example.com") | ||
return | ||
} | ||
|
||
if *timeout == 0 && *domain == "" { | ||
fmt.Println("Timeout parameter( -t ) is not set. By entering the domain, you can have it calculated automatically.") | ||
return | ||
} | ||
|
||
if *domain != "" { | ||
getDomain := modules.GetDomainTitle(*domain) | ||
if len(getDomain) == 0 { | ||
fmt.Println("Domain not resolved.") | ||
return | ||
} | ||
DomainTitle = getDomain[0] | ||
|
||
if *timeout == 0 { | ||
resolveTime, _ := strconv.Atoi(getDomain[1]) | ||
*timeout = ((resolveTime * 15) / 100) + resolveTime | ||
} | ||
} | ||
|
||
if *ip != "" { | ||
splitIP := strings.Split(*ip, ",") | ||
tools.FindIP(splitIP, *domain, DomainTitle, *con, *export, *timeout) | ||
return | ||
} | ||
|
||
if *asn != "" { | ||
tools.FindASN(*asn, *domain, DomainTitle, *con, *export, *timeout) | ||
return | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package modules | ||
|
||
import "net" | ||
|
||
func CalcIPAddress(cidr string) ([]string, error) { | ||
ip, ipnet, err := net.ParseCIDR(cidr) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var ips []string | ||
for ip := ip.Mask(ipnet.Mask); ipnet.Contains(ip); inc(ip) { | ||
ips = append(ips, ip.String()) | ||
} | ||
|
||
return ips[1 : len(ips)-1], nil | ||
} | ||
|
||
func inc(ip net.IP) { | ||
for j := len(ip) - 1; j >= 0; j-- { | ||
ip[j]++ | ||
if ip[j] > 0 { | ||
break | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package modules | ||
|
||
func FindIPBlocks(asn string) string { | ||
output := RequestFunc("https://www.radb.net/query?advanced_query=1&keywords="+asn+"&-T+option=&ip_option=&-i=1&-i+option=origin", "www.radb.net", 5000) | ||
if len(output) > 0 { | ||
return output[2] | ||
} | ||
|
||
return "" | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package modules | ||
|
||
import ( | ||
"regexp" | ||
) | ||
|
||
func GetDomainTitle(url string) []string { | ||
getTitle := RequestFunc("http://"+url, url, 5000) | ||
re := regexp.MustCompile(`.*?<title>(.*?)</title>.*`) | ||
|
||
if len(getTitle) > 0 { | ||
match := re.FindStringSubmatch(getTitle[2]) | ||
return []string{match[1], getTitle[3]} | ||
} | ||
|
||
return []string{} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package modules | ||
|
||
import ( | ||
"regexp" | ||
"strings" | ||
) | ||
|
||
func GetSite(ip string, domain string, timeout int) []string { | ||
requestSite := RequestFunc("http://"+ip, domain, timeout) | ||
|
||
if len(requestSite) > 0 { | ||
re := regexp.MustCompile(`.*?<title>(.*?)</title>.*`) | ||
title := re.FindStringSubmatch(requestSite[2]) | ||
if len(title) > 0 { | ||
explodeHttpCode := strings.Split(requestSite[0], " ") | ||
return []string{explodeHttpCode[0], requestSite[1], title[1]} | ||
} | ||
} | ||
|
||
return []string{} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package modules | ||
|
||
import ( | ||
"context" | ||
"github.com/corpix/uarand" | ||
"net/http" | ||
"net/http/httputil" | ||
"strconv" | ||
"time" | ||
) | ||
|
||
func RequestFunc(ip string, url string, timeout int) []string { | ||
n := time.Now() | ||
|
||
req, err := http.NewRequest("GET", ip, nil) | ||
if err != nil { | ||
return []string{} | ||
} | ||
|
||
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(timeout)*time.Millisecond) | ||
defer cancel() | ||
req = req.WithContext(ctx) | ||
|
||
req.Host = url | ||
|
||
req.Header.Set("User-Agent", uarand.GetRandom()) | ||
resp, err := http.DefaultClient.Do(req) | ||
if err != nil { | ||
return []string{} | ||
} | ||
|
||
last, err := httputil.DumpResponse(resp, true) | ||
if err != nil { | ||
return []string{} | ||
} | ||
|
||
return []string{resp.Status, ip, string(last), strconv.FormatInt(time.Since(n).Milliseconds(), 10)} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package modules | ||
|
||
import "fmt" | ||
|
||
func ResolveSite(IPAddress []string, Websites [][]string, DomainTitle string, IPBlocks []string, domain string, con bool, export bool, timeout int) { | ||
for _, ip := range IPAddress { | ||
site := GetSite(ip, domain, timeout) | ||
if len(site) > 0 { | ||
fmt.Print("+") | ||
Websites = append(Websites, site) | ||
|
||
if DomainTitle != "" && site[2] == DomainTitle && con == false { | ||
PrintResult("Search Domain by ASN", DomainTitle, timeout, IPBlocks, Websites, export) | ||
return | ||
} | ||
} else { | ||
fmt.Print("-") | ||
} | ||
} | ||
|
||
PrintResult("Search All ASN/IP", DomainTitle, timeout, IPBlocks, Websites, export) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package modules | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strconv" | ||
"strings" | ||
"time" | ||
) | ||
|
||
func exportFile(result string) { | ||
fileName := "ipmap_" + strconv.FormatInt(time.Now().Local().Unix(), 10) + "_export.txt" | ||
f, err := os.Create(fileName) | ||
if err != nil { | ||
fmt.Println("Export file creation error") | ||
return | ||
} | ||
defer f.Close() | ||
|
||
_, err = f.WriteString(result) | ||
if err != nil { | ||
fmt.Println("Export file write error") | ||
return | ||
} | ||
|
||
fmt.Println("Successfully exported: " + fileName) | ||
return | ||
|
||
} | ||
|
||
func PrintResult(method string, title string, timeout int, ipblocks []string, founded [][]string, export bool) { | ||
fmt.Println("\n") | ||
|
||
resultString := "==================== RESULT ====================" | ||
resultString += "\nMethod: " + method | ||
|
||
if title != "" { | ||
resultString += "\nSearch Site: " + title | ||
} | ||
|
||
resultString += "\nTimeout: " + strconv.Itoa(timeout) + "ms" | ||
resultString += "\nIP Blocks: " + strings.Join(ipblocks, ",") | ||
|
||
resultString += "\nFounded Websites:\n" | ||
if len(founded) > 0 { | ||
for _, site := range founded { | ||
resultString += strings.Join(site, ", ") + "\n" | ||
} | ||
} | ||
resultString += "================================================" | ||
fmt.Println(resultString) | ||
|
||
if export == true { | ||
exportFile(resultString) | ||
return | ||
} | ||
|
||
fmt.Print("\nDo you want to export result to file? (Y/n): ") | ||
var ex string | ||
_, err := fmt.Scanln(&ex) | ||
if err != nil { | ||
return | ||
} | ||
|
||
if ex == "y" || ex == "Y" || ex == "" { | ||
exportFile(resultString) | ||
} else { | ||
fmt.Println("Export canceled") | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package tools | ||
|
||
import ( | ||
"fmt" | ||
"ipmap/modules" | ||
"regexp" | ||
"strconv" | ||
"time" | ||
) | ||
|
||
var ( | ||
IPBlocks []string | ||
IPAddress []string | ||
Websites [][]string | ||
) | ||
|
||
func FindASN(asn string, domain string, domainTitle string, con bool, export bool, timeout int) { | ||
re := regexp.MustCompile(`(?m)route:\s+([0-9\.\/]+)$`) | ||
for _, match := range re.FindAllStringSubmatch(modules.FindIPBlocks(asn), -1) { | ||
IPBlocks = append(IPBlocks, match[1]) | ||
} | ||
|
||
for _, block := range IPBlocks { | ||
ips, err := modules.CalcIPAddress(block) | ||
if err != nil { | ||
return | ||
} | ||
|
||
IPAddress = append(IPAddress, ips...) | ||
} | ||
|
||
fmt.Println("ASN: " + asn + | ||
"\nIP Block: " + strconv.Itoa(len(IPBlocks)) + | ||
"\nIP Address: " + strconv.Itoa(len(IPAddress)) + | ||
"\nStart Time: " + time.Now().Local().String() + | ||
"\nEnd Time: " + time.Now().Add((time.Millisecond*time.Duration(timeout))*time.Duration(len(IPAddress))).Local().String()) | ||
|
||
modules.ResolveSite(IPAddress, Websites, domainTitle, IPBlocks, domain, con, export, timeout) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package tools | ||
|
||
import ( | ||
"fmt" | ||
"ipmap/modules" | ||
"strconv" | ||
"time" | ||
) | ||
|
||
func FindIP(IPBlocks []string, domain string, domainTitle string, con bool, export bool, timeout int) { | ||
for _, block := range IPBlocks { | ||
ips, err := modules.CalcIPAddress(block) | ||
if err != nil { | ||
return | ||
} | ||
|
||
IPAddress = append(IPAddress, ips...) | ||
} | ||
|
||
fmt.Println("IP Block: " + strconv.Itoa(len(IPBlocks)) + | ||
"\nIP Address: " + strconv.Itoa(len(IPAddress)) + | ||
"\nStart Time: " + time.Now().Local().String() + | ||
"\nEnd Time: " + time.Now().Add((time.Millisecond*time.Duration(timeout))*time.Duration(len(IPAddress))).Local().String()) | ||
|
||
modules.ResolveSite(IPAddress, Websites, domainTitle, IPBlocks, domain, con, export, timeout) | ||
} |