Content-Length: 318873 | pFad | https://github.com/mubeng/mubeng/commit/c2ccf5600528e165064b29d1ed4236390d3f5188

50 feat(checker): using ipinfo endpoint to check (fix #191) · mubeng/mubeng@c2ccf56 · GitHub
Skip to content

Commit

Permalink
feat(checker): using ipinfo endpoint to check (fix #191)
Browse files Browse the repository at this point in the history
  • Loading branch information
dwisiswant0 committed Mar 9, 2023
1 parent 6fde97b commit c2ccf56
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 19 deletions.
20 changes: 10 additions & 10 deletions internal/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func Do(opt *common.Options) {

p.Go(func() {
addr, err := check(address, opt.Timeout)
if len(opt.Countries) > 0 && !isMatchCC(opt.Countries, addr.CC) {
if len(opt.Countries) > 0 && !isMatchCC(opt.Countries, addr.Country) {
return
}

Expand All @@ -36,7 +36,7 @@ func Do(opt *common.Options) {
fmt.Printf("[%s] %s\n", aurora.Red("DIED"), address)
}
} else {
fmt.Printf("[%s] [%s] [%s] %s\n", aurora.Green("LIVE"), aurora.Magenta(addr.CC), aurora.Cyan(addr.IP), address)
fmt.Printf("[%s] [%s] [%s] %s\n", aurora.Green("LIVE"), aurora.Magenta(addr.Country), aurora.Cyan(addr.IP), address)

if opt.Output != "" {
fmt.Fprintf(opt.Result, "%s\n", address)
Expand All @@ -62,15 +62,15 @@ func isMatchCC(cc []string, code string) bool {
return false
}

func check(address string, timeout time.Duration) (myIP, error) {
func check(address string, timeout time.Duration) (IPInfo, error) {
req, err := http.NewRequest("GET", endpoint, nil)
if err != nil {
return myip, err
return ipinfo, err
}

tr, err := mubeng.Transport(address)
if err != nil {
return myip, err
return ipinfo, err
}

proxy := &mubeng.Proxy{
Expand All @@ -84,21 +84,21 @@ func check(address string, timeout time.Duration) (myIP, error) {

resp, err := client.Do(req)
if err != nil {
return myip, err
return ipinfo, err
}

body, err := io.ReadAll(resp.Body)
if err != nil {
return myip, err
return ipinfo, err
}

err = json.Unmarshal([]byte(body), &myip)
err = json.Unmarshal([]byte(body), &ipinfo)
if err != nil {
return myip, err
return ipinfo, err
}

defer resp.Body.Close()
defer tr.CloseIdleConnections()

return myip, nil
return ipinfo, nil
}
13 changes: 13 additions & 0 deletions internal/checker/ipinfo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package checker

type IPInfo struct {
City string `json:"city"`
Country string `json:"country"`
Hostname string `json:"hostname"`
IP string `json:"ip"`
Loc string `json:"loc"`
Org string `json:"org"`
Readme string `json:"readme"`
Region string `json:"region"`
Timezone string `json:"timezone"`
}
7 changes: 0 additions & 7 deletions internal/checker/myip.go

This file was deleted.

4 changes: 2 additions & 2 deletions internal/checker/vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

var (
client *http.Client
myip myIP
ipinfo IPInfo

endpoint = "https://api.myip.com/"
endpoint = "https://ipinfo.io/json"
)

0 comments on commit c2ccf56

Please sign in to comment.








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/mubeng/mubeng/commit/c2ccf5600528e165064b29d1ed4236390d3f5188

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy