Skip to content

Commit c761038

Browse files
authored
fixed file,api checking fmt
Output now writes newline at exit
1 parent a4e483b commit c761038

File tree

4 files changed

+87
-73
lines changed

4 files changed

+87
-73
lines changed

bufio_scanner.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"log"
1313
"net/http"
1414
"os"
15+
"strings"
1516
)
1617

1718
func Scanner() {
@@ -34,15 +35,13 @@ func Scanner() {
3435
}
3536
} else if *input != "" {
3637
fmt.Printf("Detected FILE Mode.\n")
37-
f, err := os.Open(*input)
38+
b, err := os.ReadFile(*input)
3839
if err != nil {
3940
log.Fatalln("open file err")
4041
}
41-
defer f.Close()
42-
scanner := bufio.NewScanner(f)
43-
for scanner.Scan() {
44-
ip := scanner.Text()
45-
queueChan <- ip
42+
lines := strings.Split(string(b), "\n")
43+
for _, line := range lines {
44+
queueChan <- line
4645
}
4746
} else {
4847
fmt.Printf("Detected ZMAP Mode.\n")

exporter.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ func (e *Exporter) create() {
2424
}
2525
}
2626

27+
func (e *Exporter) Close() {
28+
e.f.WriteString("\n")
29+
e.f.Close()
30+
}
31+
2732
func (e *Exporter) Add(s string) {
2833
_, err := e.f.WriteString(s + "\n")
2934
if err != nil {

http.go

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,17 @@ func (p *Proxy) CheckProxyHTTP(proxy string) {
7171
atomic.AddUint64(&checked, 1)
7272
}()
7373

74-
proxyPort := *port
74+
var err error
75+
var proxyPort = *port
7576
s := strings.Split(proxy, ":")
77+
if len(s) > 1 {
78+
proxyPort, err = strconv.Atoi(s[1])
79+
if err != nil {
80+
log.Println(err)
81+
return
82+
}
83+
}
84+
7685
if len(s) > 1 {
7786
var err error
7887
proxyPort, err = strconv.Atoi(s[1])
@@ -125,7 +134,7 @@ func (p *Proxy) CheckProxyHTTP(proxy string) {
125134
go PrintProxy(s[0], proxyPort)
126135
}
127136
atomic.AddUint64(&success, 1)
128-
exporter.Add(fmt.Sprintf("%s:%d", proxy, *port))
137+
exporter.Add(fmt.Sprintf("%s:%d", s[0], proxyPort))
129138
}
130139
}
131140

@@ -136,10 +145,10 @@ func (p *Proxy) CheckProxySocks4(proxy string) {
136145
atomic.AddUint64(&checked, 1)
137146
}()
138147

139-
proxyPort := *port
148+
var err error
149+
var proxyPort = *port
140150
s := strings.Split(proxy, ":")
141151
if len(s) > 1 {
142-
var err error
143152
proxyPort, err = strconv.Atoi(s[1])
144153
if err != nil {
145154
log.Println(err)
@@ -180,7 +189,7 @@ func (p *Proxy) CheckProxySocks4(proxy string) {
180189
go PrintProxy(s[0], proxyPort)
181190
}
182191
atomic.AddUint64(&success, 1)
183-
exporter.Add(fmt.Sprintf("%s:%d", proxy, *port))
192+
exporter.Add(fmt.Sprintf("%s:%d", s[0], proxyPort))
184193
}
185194
}
186195

@@ -191,10 +200,10 @@ func (p *Proxy) CheckProxySocks5(proxy string) {
191200
atomic.AddUint64(&checked, 1)
192201
}()
193202

194-
proxyPort := *port
203+
var err error
204+
var proxyPort = *port
195205
s := strings.Split(proxy, ":")
196206
if len(s) > 1 {
197-
var err error
198207
proxyPort, err = strconv.Atoi(s[1])
199208
if err != nil {
200209
log.Println(err)
@@ -235,6 +244,6 @@ func (p *Proxy) CheckProxySocks5(proxy string) {
235244
go PrintProxy(s[0], proxyPort)
236245
}
237246
atomic.AddUint64(&success, 1)
238-
exporter.Add(fmt.Sprintf("%s:%d", proxy, *port))
247+
exporter.Add(fmt.Sprintf("%s:%d", s[0], proxyPort))
239248
}
240249
}

main.go

Lines changed: 60 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
/*
2-
(c) Yariya
2+
(c) Yariya
33
*/
44

55
package main
66

77
import (
8-
"encoding/json"
9-
"flag"
10-
"fmt"
11-
"log"
12-
"math/rand"
13-
"os"
14-
"os/signal"
15-
"strings"
16-
"time"
8+
"encoding/json"
9+
"flag"
10+
"fmt"
11+
"log"
12+
"math/rand"
13+
"os"
14+
"os/signal"
15+
"strings"
16+
"time"
1717
)
1818

1919
var port = flag.Int("p", 80, "proxy port")
@@ -26,66 +26,67 @@ var fetch = flag.String("url", "", "url proxy fetch")
2626
const wt = 3
2727

2828
type Api struct {
29-
Status string `json:"Status"`
30-
Reason string `json:"Reason"`
29+
Status string `json:"Status"`
30+
Reason string `json:"Reason"`
3131
}
3232

3333
type Config struct {
34-
CheckSite string `json:"check-site"`
35-
ProxyType string `json:"proxy-type"`
36-
HttpThreads int `json:"http_threads"`
37-
Headers struct {
38-
UserAgent string `json:"user-agent"`
39-
Accept string `json:"accept"`
40-
} `json:"headers"`
41-
PrintIps struct {
42-
Enabled bool `json:"enabled"`
43-
DisplayIpInfo bool `json:"display-ip-info"`
44-
} `json:"print_ips"`
45-
Timeout struct {
46-
HttpTimeout int `json:"http_timeout"`
47-
Socks4Timeout int `json:"socks4_timeout"`
48-
Socks5Timeout int `json:"socks5_timeout"`
49-
} `json:"timeout"`
34+
CheckSite string `json:"check-site"`
35+
ProxyType string `json:"proxy-type"`
36+
HttpThreads int `json:"http_threads"`
37+
Headers struct {
38+
UserAgent string `json:"user-agent"`
39+
Accept string `json:"accept"`
40+
} `json:"headers"`
41+
PrintIps struct {
42+
Enabled bool `json:"enabled"`
43+
DisplayIpInfo bool `json:"display-ip-info"`
44+
} `json:"print_ips"`
45+
Timeout struct {
46+
HttpTimeout int `json:"http_timeout"`
47+
Socks4Timeout int `json:"socks4_timeout"`
48+
Socks5Timeout int `json:"socks5_timeout"`
49+
} `json:"timeout"`
5050
}
5151

5252
var config Config
5353

5454
func main() {
55-
if strings.Contains(strings.Join(os.Args[0:], ""), "-h") {
56-
fmt.Printf("\t\tZmap ProxyScanner @tcpfin\nHelp:\n\t-p <port> - Port you want to scan.\n\t-o <proxies.txt> - Writes proxy hits to file.\n\n\t-input <proxies.txt> - Loads the proxy list and checks it.\n\t-url https://api.com/proxies - Loads the proxies from an api and checks it.\n\n\tconfig.json - Customize the whole proxy checker\n")
57-
return
58-
}
59-
flag.Parse()
60-
rand.Seed(time.Now().UnixNano())
55+
if strings.Contains(strings.Join(os.Args[0:], ""), "-h") {
56+
fmt.Printf("\t\tZmap ProxyScanner @tcpfin\nHelp:\n\t-p <port> - Port you want to scan.\n\t-o <proxies.txt> - Writes proxy hits to file.\n\n\t-input <proxies.txt> - Loads the proxy list and checks it.\n\t-url https://api.com/proxies - Loads the proxies from an api and checks it.\n\n\tconfig.json - Customize the whole proxy checker\n")
57+
return
58+
}
59+
flag.Parse()
60+
rand.Seed(time.Now().UnixNano())
6161

62-
cfgBytes, err := os.ReadFile(*configFile)
63-
if err != nil {
64-
log.Println("error while opening config file")
65-
return
66-
}
67-
err = json.Unmarshal(cfgBytes, &config)
68-
if err != nil {
69-
fmt.Println("error while parsing config json")
70-
return
71-
}
62+
cfgBytes, err := os.ReadFile(*configFile)
63+
if err != nil {
64+
log.Println("error while opening config file")
65+
return
66+
}
67+
err = json.Unmarshal(cfgBytes, &config)
68+
if err != nil {
69+
fmt.Println("error while parsing config json")
70+
return
71+
}
7272

73-
_ = os.Remove(*output)
73+
_ = os.Remove(*output)
7474

75-
exporter = &Exporter{
76-
out: *output,
77-
}
75+
exporter = &Exporter{
76+
out: *output,
77+
}
7878

79-
go exporter.create()
80-
go Queue()
81-
go Scanner()
82-
for x := 0; x < wt; x++ {
83-
go Proxies.WorkerThread()
84-
}
85-
go Stater()
86-
time.Sleep(time.Second)
79+
go exporter.create()
80+
go Queue()
81+
go Scanner()
82+
for x := 0; x < wt; x++ {
83+
go Proxies.WorkerThread()
84+
}
85+
go Stater()
86+
time.Sleep(time.Second)
8787

88-
sc := make(chan os.Signal, 1)
89-
signal.Notify(sc, os.Kill, os.Interrupt)
90-
<-sc
88+
sc := make(chan os.Signal, 1)
89+
signal.Notify(sc, os.Kill, os.Interrupt)
90+
<-sc
91+
exporter.Close()
9192
}

0 commit comments

Comments
 (0)