Skip to content

Commit

Permalink
advanced usage and bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsonz committed Jun 6, 2017
1 parent a4d23e4 commit 6ab9c95
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
## 说明
用于扫描SNI服务器,sniip_ok.txt中的延迟值为配置中指定的各server_name的延迟的平均值。

由于在初始化时读取了所有ip以便执行去重操作,所以会消耗大量的内存,对于需要扫描大量ip且机器性能不够强大的用户,请将'soft_mode'置为'true'
由于在初始化时读取了所有ip以便执行去重操作,所以会消耗大量的内存,对于需要扫描大量ip且机器性能不够强大的用户,请将`soft_mode`置为`true`

请将待测试的ip段放到sniip.txt文件,支持以下ip格式:

Expand All @@ -31,7 +31,8 @@ SUPPORT COMMANDS:
-h, --help help message
-a, --allhostname lookup all hostname of ip, or lookup the first one by default
-r, --override override settings
-m, --softmode reduce memory usage
SUPPORT VARS:
-i, --snifile<=path> put your ip ranges into this file
-o, --outputfile<=path> output sni ip to this file
Expand All @@ -48,7 +49,9 @@ SUPPORT VARS:

`"delay":1200` 扫描完成后,提取所有小于等于该延迟的ip

`"server_name"` 用于测试SNI服务器的域名
`"server_name"` 用于测试SNI服务器的域名,以逗号分隔

`"soft_mode"` 边读取ip边扫描,适合需要扫描大量ip且内存较小的用户

## Wiki
[Wiki](https://plumwine.me/go-sni-detector-usage-wiki/)
Expand Down
3 changes: 2 additions & 1 deletion message.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ const (
allHostnameMsg string = "lookup all hostname of ip"
overrideMsg string = "override settings"
sniFileMsg string = "ip range file (default: sniip.txt)"
outputFileMsg string = "output sni ip file (default: sniip_output.txt)"
outputFileMsg string = "output sni ip file (default: sniip_ok.txt)"
jsonFileMsg string = "output json sni ip file (default: ip.txt)"
concurrencyMsg string = "concurrency"
timeoutMsg string = "timeout"
handshakeTimeoutMsg string = "handshake timeout"
delayMsg string = "delay"
serverNameMsg string = "comma-separated server names"
softModeMsg string = "reduce memory usage"
)
19 changes: 13 additions & 6 deletions sni.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func main() {
}

if config.SoftMode {
totalips = make(chan string, config.Concurrency*10)
totalips = make(chan string, config.Concurrency)
go func() {
for _, ip := range lastOKIP {
totalips <- ip
Expand Down Expand Up @@ -285,14 +285,16 @@ func updateConfig(isOverride bool) {
fmt.Sprintf(`{
"concurrency":%d,
"timeout":%d,
"handshake_timeout":%d,
"delay":%d,
"server_name":[
%s
],
"sort_by_delay":true,
"always_check_all_ip":false
}`, config.Concurrency, config.Timeout, config.Delay,
fmt.Sprint("\"", strings.Join(config.ServerName, "\",\n \""), "\"")), configFileName)
"sort_by_delay":%t,
"always_check_all_ip":%t,
"soft_mode":%t
}`, config.Concurrency, config.Timeout, config.HandshakeTimeout, config.Delay,
fmt.Sprint("\"", strings.Join(config.ServerName, "\",\n \""), "\""), config.SortByDelay, config.AlwaysCheck, config.SoftMode), configFileName)
fmt.Println("update sni.json successfully")
}
}
Expand Down Expand Up @@ -359,6 +361,7 @@ SUPPORT COMMANDS:
-h, --help %s
-a, --allhostname %s
-r, --override %s
-m, --softmode %s
SUPPORT VARS:
-i, --snifile %s
Expand All @@ -369,7 +372,7 @@ SUPPORT VARS:
-ht, --handshaketimeout %s (default: %dms)
-d, --delay %s (default: %dms)
-s, --servername %s (default: %s)
`, helpMsg, allHostnameMsg, overrideMsg, sniFileMsg, outputFileMsg, jsonFileMsg, concurrencyMsg, config.Concurrency, timeoutMsg, config.Timeout, handshakeTimeoutMsg, config.HandshakeTimeout, delayMsg, config.Delay, serverNameMsg, strings.Join(config.ServerName, ", "))
`, helpMsg, allHostnameMsg, overrideMsg, softModeMsg, sniFileMsg, outputFileMsg, jsonFileMsg, concurrencyMsg, config.Concurrency, timeoutMsg, config.Timeout, handshakeTimeoutMsg, config.HandshakeTimeout, delayMsg, config.Delay, serverNameMsg, strings.Join(config.ServerName, ", "))
}
var (
outputAllHostname bool
Expand All @@ -382,6 +385,7 @@ SUPPORT VARS:
delay int
serverNames string
isOverride bool
softMode bool
)

flag.BoolVar(&outputAllHostname, "a", false, allHostnameMsg)
Expand All @@ -404,6 +408,8 @@ SUPPORT VARS:
flag.StringVar(&serverNames, "servername", strings.Join(config.ServerName, ", "), serverNameMsg)
flag.BoolVar(&isOverride, "r", false, overrideMsg)
flag.BoolVar(&isOverride, "override", false, overrideMsg)
flag.BoolVar(&softMode, "m", config.SoftMode, overrideMsg)
flag.BoolVar(&softMode, "softmode", config.SoftMode, overrideMsg)

flag.Set("logtostderr", "true")
flag.Parse()
Expand All @@ -428,6 +434,7 @@ SUPPORT VARS:
}
config.ServerName = sNs
config.IsOverride = isOverride
config.SoftMode = softMode
}
func getInputFromCommand() string {
reader := bufio.NewReader(os.Stdin)
Expand Down

0 comments on commit 6ab9c95

Please sign in to comment.