-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
16 changed files
with
731 additions
and
1 deletion.
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
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 |
---|---|---|
@@ -1,2 +1,84 @@ | ||
# cIPR | ||
将域名转为ip段权重 | ||
|
||
> 第一次使用回自动下载 `qqwry.dat` 和生成配置文件,不好的网络环境会影响使用 | ||
## 用法 | ||
|
||
``` | ||
admin@admin cIPR % go run cIPR.go domain.txt | ||
▄████████ ▄█ ▄███████▄ ▄████████ | ||
███ ███ ███ ███ ███ ███ ███ | ||
███ █▀ ███▌ ███ ███ ███ ███ | ||
███ ███▌ ███ ███ ▄███▄▄▄▄██▀ | ||
███ ███▌ ▀█████████▀ ▀▀███▀▀▀▀▀ | ||
███ █▄ ███ ███ ▀███████████ | ||
███ ███ ███ ███ ███ ███ | ||
████████▀ █▀ ▄████▀ ███ ███ | ||
███ ███ | ||
v0.0.1 | ||
https://github.com/canc3s/cIPR | ||
www.xxx.com [103.x.x.x] | ||
test.xxx.com [103.x.x.x] | ||
... | ||
124.x.x.0/24 || 194 | ||
223.x.x.0/24 || 74 | ||
219.x.x.0/24 || 51 | ||
106.x.x.0/24 || 37 | ||
111.x.x.0/24 || 37 | ||
202.x.x.0/24 || 34 | ||
103.x.x.0/24 || 25 | ||
1.x.x.0/24 || 21 | ||
103.x.x.0/24 || 15 | ||
101.x.x.0/24 || 12 | ||
125.x.x.0/24 || 8 | ||
112.x.x.0/24 || 8 | ||
210.x.x.0/24 || 6 | ||
27.x.x.0/24 || 6 | ||
124.x.x.0/24 || 5 | ||
42.x.x.0/24 || 5 | ||
106.x.x.0/24 || 5 | ||
58.x.x.0/24 || 4 | ||
221.x.x.0/24 || 3 | ||
219.x.x.0/24 || 2 | ||
118.x.x.0/24 || 2 | ||
220.x.x.0/24 || 2 | ||
124.x.x.0/24 || 2 | ||
123.x.x.0/24 || 2 | ||
36.x.x.0/24 || 2 | ||
59.x.x.0/24 || 1 | ||
58.x.x.0/24 || 1 | ||
106.x.x.0/24 || 1 | ||
211.x.x.0/24 || 1 | ||
123.x.x.0/24 || 1 | ||
``` | ||
|
||
## config.yml | ||
|
||
```yaml | ||
datPath: ./qqwry.dat #qqwry.dat的位置 | ||
blackList: #ip段黑名单 | ||
- 阿里巴巴 | ||
- CDN | ||
- 局域网 | ||
- 美国 | ||
- 阿里 | ||
- Azure | ||
- 华为 | ||
- 腾讯 | ||
- Microsoft | ||
- 微软 | ||
- 网宿 | ||
- Amazon | ||
``` | ||
该黑名单屏蔽了cnd和一些云服务器,使用时可以自行调节设置。 | ||
## Thanks | ||
- [Nali](https://github.com/zu1k/nali) | ||
- [纯真QQIP离线数据库](http://www.cz88.net/fox/ipdat.shtml) |
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,64 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"github.com/canc3s/cIPR/internal/app" | ||
"github.com/canc3s/cIPR/internal/tools" | ||
"net" | ||
"sort" | ||
"strings" | ||
) | ||
|
||
|
||
func main() { | ||
options := app.ParseOptions() | ||
scanner := tools.FileScaner(options.InputFile) | ||
var ( | ||
ipRecords []net.IP | ||
) | ||
for scanner.Scan() { | ||
domain := strings.TrimSpace(scanner.Text()) | ||
ipRecord, _ :=net.LookupIP(domain) | ||
fmt.Println(domain,"\t",ipRecord) | ||
ipRecords = append(ipRecords,ipRecord...) | ||
} | ||
ips := tools.RemoveDuplicateIP(ipRecords) | ||
|
||
app.InitIPDB(options.DatPath) | ||
ress := make(map[string]int) | ||
for _, ip := range ips { | ||
result := app.ParseIP(ip) | ||
flag := true | ||
for _, keyWord := range options.BlackList { | ||
if strings.Contains(result, keyWord) { | ||
flag = false | ||
break | ||
} | ||
} | ||
if flag && tools.ValidIP(ip) { | ||
buf := strings.Split(ip,".") | ||
ipd := strings.Join(buf[:3] , ".") | ||
ipd += ".0/24" | ||
ress[ipd]++ | ||
} | ||
} | ||
|
||
type IPR struct { | ||
ip string | ||
count int | ||
} | ||
|
||
var lstIPR []IPR | ||
|
||
for k, v := range ress { | ||
lstIPR = append(lstIPR, IPR {k, v}) | ||
} | ||
|
||
sort.Slice(lstIPR, func(i, j int) bool { | ||
return lstIPR[i].count > lstIPR[j].count // 降序 | ||
}) | ||
|
||
for _, i := range lstIPR { | ||
fmt.Printf("%-18s||%4d\n",i.ip, i.count) | ||
} | ||
} |
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,14 @@ | ||
datPath: ./qqwry.dat | ||
blackList: | ||
- 阿里巴巴 | ||
- CDN | ||
- 局域网 | ||
- 美国 | ||
- 阿里 | ||
- Azure | ||
- 华为 | ||
- 腾讯 | ||
- Microsoft | ||
- 微软 | ||
- 网宿 | ||
- Amazon |
Binary file not shown.
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,8 @@ | ||
module github.com/canc3s/cIPR | ||
|
||
go 1.15 | ||
|
||
require ( | ||
golang.org/x/text v0.3.5 | ||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b | ||
) |
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,7 @@ | ||
golang.org/x/text v0.3.5 h1:i6eZZ+zk0SOf0xgBpEpPD18qWcJda6q1sxt3S0kzyUQ= | ||
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= | ||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= | ||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
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,54 @@ | ||
package app | ||
|
||
import ( | ||
"github.com/canc3s/cIPR/internal/tools" | ||
"gopkg.in/yaml.v3" | ||
"io/ioutil" | ||
"log" | ||
) | ||
|
||
const ( | ||
ConfigFile = "./config.yml" | ||
) | ||
|
||
type Config struct { | ||
DatPath string `yaml:"datPath"` | ||
BlackList []string `yaml:"blackList"` | ||
} | ||
|
||
func InitConf(option *Options) { | ||
if !tools.FileExists(ConfigFile) { | ||
DefaultConf() | ||
} | ||
err := LoadConf(option) | ||
if err != nil { | ||
log.Fatalf("error: %v", err) | ||
} | ||
} | ||
|
||
func DefaultConf() { | ||
config := &Config{ | ||
"./qqwry.dat", | ||
[]string{"阿里巴巴","CDN","局域网","美国","阿里","Azure","华为","腾讯","Microsoft","微软","网宿","Amazon"}, | ||
} | ||
d, err := yaml.Marshal(config) | ||
if err != nil { | ||
log.Fatalf("error: %v", err) | ||
} | ||
ioutil.WriteFile(ConfigFile, d, 0644) | ||
} | ||
|
||
func LoadConf(option *Options) error { | ||
yamlFile, err := ioutil.ReadFile(ConfigFile) | ||
config := &Config{} | ||
if err != nil { | ||
return err | ||
} | ||
err = yaml.Unmarshal(yamlFile, config) | ||
if err != nil { | ||
return err | ||
} | ||
option.DatPath = config.DatPath | ||
option.BlackList = config.BlackList | ||
return nil | ||
} |
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,66 @@ | ||
package app | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"github.com/canc3s/cIPR/internal/tools" | ||
"github.com/canc3s/cIPR/pkg/qqwry" | ||
"log" | ||
) | ||
|
||
const banner = ` | ||
▄████████ ▄█ ▄███████▄ ▄████████ | ||
███ ███ ███ ███ ███ ███ ███ | ||
███ █▀ ███▌ ███ ███ ███ ███ | ||
███ ███▌ ███ ███ ▄███▄▄▄▄██▀ | ||
███ ███▌ ▀█████████▀ ▀▀███▀▀▀▀▀ | ||
███ █▄ ███ ███ ▀███████████ | ||
███ ███ ███ ███ ███ ███ | ||
████████▀ █▀ ▄████▀ ███ ███ | ||
███ ███ | ||
v` | ||
|
||
// Version is the current version of C | ||
const Version = `0.0.1` | ||
|
||
type Options struct { | ||
BlackList []string | ||
DatPath string // Target is a single URL/Domain to scan usng a template | ||
InputFile string // Targets specifies the targets to scan using templates. | ||
Silent bool | ||
} | ||
|
||
func ParseOptions() *Options { | ||
options := &Options{} | ||
showBanner() | ||
flag.Parse() | ||
|
||
options.InputFile = flag.Arg(0) | ||
|
||
InitConf(options) | ||
options.validateOptions() | ||
|
||
return options | ||
} | ||
|
||
func (options *Options) validateOptions() { | ||
if options.DatPath != "" && !tools.FileExists(options.DatPath) { | ||
log.Println("文件 ", options.DatPath, " 文件不存在,尝试从网络获取最新纯真 IP 库") | ||
qqwry.Download(options.DatPath) | ||
} | ||
if options.InputFile == "" { | ||
log.Fatalf("用法:\t./cIPR domain.txt\n\n") | ||
} | ||
if options.InputFile != "" && !tools.FileExists(options.InputFile) { | ||
log.Fatalf("文件 %s 不存在!\n", options.InputFile) | ||
} | ||
} | ||
|
||
// showBanner is used to show the banner to the user | ||
func showBanner() { | ||
fmt.Printf("%s%s\n", banner,Version) | ||
fmt.Printf("\thttps://github.com/canc3s/cIPR\n") | ||
|
||
//gologger.Labelf("请谨慎使用,您应对自己的行为负责\n") | ||
//gologger.Labelf("开发人员不承担任何责任,也不对任何滥用或损坏负责.\n") | ||
} |
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,33 @@ | ||
package app | ||
|
||
import ( | ||
"github.com/canc3s/cIPR/internal/tools" | ||
"github.com/canc3s/cIPR/pkg/qqwry" | ||
"path/filepath" | ||
) | ||
|
||
type IPDB interface { | ||
Find(ip string) string | ||
} | ||
|
||
var ( | ||
db IPDB | ||
qqip qqwry.QQwry | ||
) | ||
|
||
// init ip db content | ||
func InitIPDB(datPath string) { | ||
db = qqwry.NewQQwry(filepath.Join(datPath)) | ||
} | ||
|
||
// parse several ips | ||
func ParseIP(ip string) string { | ||
db := db | ||
|
||
if tools.ValidIP(ip) { | ||
result := db.Find(ip) | ||
return result | ||
}else{ | ||
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,39 @@ | ||
package tools | ||
|
||
import ( | ||
"bufio" | ||
"log" | ||
"os" | ||
) | ||
|
||
// FileExists checks if a file exists and is not a directory | ||
func FileExists(filename string) bool { | ||
info, err := os.Stat(filename) | ||
if os.IsNotExist(err) { | ||
return false | ||
} | ||
return !info.IsDir() | ||
} | ||
|
||
// FolderExists checks if a folder exists | ||
func FileScaner(inputFile string) *bufio.Scanner { | ||
var ( | ||
finput *os.File | ||
scanner *bufio.Scanner | ||
err error | ||
) | ||
|
||
if FileExists(inputFile) { | ||
finput, err = os.Open(inputFile) | ||
if err != nil { | ||
log.Fatalf("Could read input file '%s': %s\n", inputFile, err) | ||
} | ||
scanner = bufio.NewScanner(finput) | ||
return scanner | ||
} else { | ||
log.Fatalf("输入的文件有问题") | ||
} | ||
return nil | ||
} | ||
|
||
|
Oops, something went wrong.