-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement hotomoe-speedchecker
- Loading branch information
1 parent
cdc5f40
commit cf370cf
Showing
7 changed files
with
159 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,16 @@ | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.go] | ||
indent_style = tab | ||
|
||
[*.bat] | ||
end_of_line = crlf | ||
charset = unset |
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 @@ | ||
dist |
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,33 @@ | ||
{ | ||
"Icons": [ | ||
{ | ||
"ID": 1, | ||
"Path": "assets/icon.ico" | ||
} | ||
], | ||
"VersionInfos": [ | ||
{ | ||
"ID": 1, | ||
"StringTables": [ | ||
{ | ||
"Language": "0409", | ||
"Charset": "04b0", | ||
"Strings": { | ||
"CompanyName": "hotomoe", | ||
"FileDescription": "hotomoe network checker", | ||
"InternalName": "hotomoe-speedchecker", | ||
"LegalCopyright": "\u00a9 hotomoe, All rights reserved.", | ||
"OriginalFilename": "hotomoe-network-checker.exe", | ||
"ProductName": "hotomoe-network-checker" | ||
} | ||
} | ||
], | ||
"Translations": [ | ||
{ | ||
"Language": "0409", | ||
"Charset": "04b0" | ||
} | ||
] | ||
} | ||
] | ||
} |
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,3 @@ | ||
module hotomoe-speedchecker | ||
|
||
go 1.20 |
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,95 @@ | ||
package main | ||
|
||
import ( | ||
"bufio" | ||
"context" | ||
"crypto/tls" | ||
"encoding/json" | ||
"net" | ||
"net/http" | ||
"os" | ||
"time" | ||
) | ||
|
||
type IfconfigInfo struct { | ||
IP string `json:"ip"` | ||
IPDecimal int `json:"ip_decimal"` | ||
Country string `json:"country"` | ||
CountryIso string `json:"country_iso"` | ||
CountryEu bool `json:"country_eu"` | ||
Asn string `json:"asn"` | ||
AsnOrg string `json:"asn_org"` | ||
Hostname string `json:"hostname"` | ||
} | ||
|
||
func main() { | ||
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true} | ||
|
||
hosts := []string{"hoto.moe", "jp1.hotomoe.net", "us1.hotomoe.net", "jp1-cf.hotomoe.net", "us1-cf.hotomoe.net"} | ||
|
||
info, err := getIfconfigInfo("") | ||
if err == nil { | ||
println("Client IP:", info.IP) | ||
println("Client Country:", info.Country) | ||
println("Client ASN:", info.Asn) | ||
} else { | ||
panic("Failed to get client IP") | ||
} | ||
|
||
println() | ||
|
||
for _, host := range hosts { | ||
println("Host:", host) | ||
|
||
ip := getIpAddress(host) | ||
println("IP:", ip) | ||
|
||
info, err := getIfconfigInfo(ip) | ||
if err == nil { | ||
println("ASN:", info.Asn) | ||
} | ||
latency := getLatency(host) | ||
println("Latency:", latency, "ms") | ||
|
||
println() | ||
} | ||
|
||
println("Press Enter to exit") | ||
bufio.NewReader(os.Stdin).ReadBytes('\n') | ||
} | ||
|
||
func getLatency(host string) int64 { | ||
currentTime := time.Now().UnixMilli() | ||
|
||
resp, err := http.Get("https://" + host) | ||
if err != nil { | ||
return -1 | ||
} | ||
defer resp.Body.Close() | ||
|
||
latency := time.Now().UnixMilli() - currentTime | ||
|
||
return latency | ||
} | ||
|
||
func getIpAddress(dnsName string) string { | ||
ips, err := net.DefaultResolver.LookupNetIP(context.Background(), "ip4", dnsName) | ||
if err != nil { | ||
return "unknown" | ||
} | ||
return ips[0].String() | ||
} | ||
|
||
func getIfconfigInfo(ip string) (IfconfigInfo, error) { | ||
var info IfconfigInfo | ||
|
||
resp, err := http.Get("https://ifconfig.co/json?ip=" + ip) | ||
if err != nil { | ||
return info, err | ||
} | ||
defer resp.Body.Close() | ||
|
||
json.NewDecoder(resp.Body).Decode(&info) | ||
|
||
return info, 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,11 @@ | ||
for /f "delims=" %%A in ('git rev-parse --show-toplevel') do (cd %%A) | ||
copy /Y assets\syso.json syso.json | ||
%USERPROFILE%\go\bin\syso.exe | ||
del syso.json | ||
SET GOOS=windows& go build -ldflags "-s -w" -o "dist/hnc-windows-amd64.exe" | ||
SET GOOS=linux& go build -ldflags "-s -w" -o "dist/hnc-linux-amd64" | ||
SET GOOS=darwin& go build -ldflags "-s -w" -o "dist/hnc-darwin-amd64" | ||
del out.syso | ||
upx --best --lzma "dist/hnc-windows-amd64.exe" | ||
upx --best --lzma "dist/hnc-linux-amd64" | ||
REM upx --best --lzma "dist/hnc-darwin-amd64" |