forked from ch4rkov/consulta-operadora
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
76 lines (60 loc) · 1.78 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package main
import (
"consulta-operadora/funcs"
"flag"
"fmt"
"html"
"os"
"strings"
)
var logo = `
_ _ _ _ _ _ ___ ____ ____ ____ ____ _ _
| | |\ | |_/ |__] |___ |__/ [__ | | |\ |
|__| | \| | \_ | |___ | \ ___] |__| | \|
`
func init() {
funcs.Message(logo, "purple")
}
func main() {
var version bool
flag.BoolVar(&version, "version", false, "Software version.")
flag.BoolVar(&version, "v", false, "Software version.")
phone := flag.String("phone", "", "Phone to search.")
flag.Parse()
if version {
funcs.Message("[!] version 1.0", "white")
os.Exit(0)
}
if *phone == "" {
funcs.Message("[!] no phone number found", "red")
os.Exit(0)
}
if !funcs.IsValidPhone(*phone) {
funcs.Message("[!] enter a valid phone number", "red")
os.Exit(0)
}
// do post request
data, time, status := funcs.DoPost(*phone)
// remove html entities
data = html.UnescapeString(data)
// check status code
if status != 200 {
funcs.Message("[!] statusCode is not 200", "red")
os.Exit(0)
}
fmt.Println(fmt.Sprintf("req delay => %s", time))
if strings.Contains(data, "Aguarde") {
time, _ := funcs.GetStr(data, `<span class="lead laranja" id="span_tempo">`, `</span>`)
funcs.Message("[!] wait "+time+"s and try again", "yellow")
os.Exit(0)
}
operadora, _ := funcs.GetStr(data, `<span class="azul lead">Operadora:</span><span class="lead laranja">`, `</span>`)
portado, _ := funcs.GetStr(data, `<span class="azul lead">Portado:</span><span class="lead laranja">`, `</span>`)
// remove spaces from the beginning
operadora = strings.TrimSpace(operadora)
portado = strings.TrimSpace(portado)
// to lower case
operadora = strings.ToLower(operadora)
portado = strings.ToLower(portado)
funcs.Message("["+*phone+"] operadora: "+operadora+" - portado: "+portado, "green")
}