-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathChangeTower.go
149 lines (142 loc) · 3.8 KB
/
ChangeTower.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package main
import (
"bufio"
"crypto/tls"
"fmt"
"io"
"log"
"net/http"
"os"
"sync"
"time"
"flag"
"github.com/rapidloop/skv"
)
var wg sync.WaitGroup
var mut sync.Mutex
func Database(link string, length string, d bool, l bool){
var old string
store, _ := skv.Open("len.db")
_ = store.Get(link, &old)
if old == ""{
if d == false{
log.Printf("New %s\n",link)
}
if l == false{
fmt.Printf("New %s\n",link)
}else{
fmt.Printf("%s\n",link)
}
_ = store.Put(link, length)
}else{
switch old {
case length:
default:
_ = store.Delete(link)
_ = store.Put(link, length)
if d == false{
log.Printf("Changed %s\n",link)
}
if l == false{
fmt.Printf("Changed %s\n",link)
}else{
fmt.Printf("%s\n",link)
}
}
}
err := store.Close()
if err != nil {
log.Fatal(err)
}
}
func Length(link string, d bool, l bool) {
defer wg.Done()
resp, err := http.Get(link)
if resp == nil {
if err != nil {
log.Fatal(err)
}
length := "0"
mut.Lock()
defer mut.Unlock()
Database(link,length,d,l)
} else {
if err != nil {
log.Fatal(err)
}
defer func(Body io.ReadCloser) {
err := Body.Close()
if err != nil {
log.Fatal(err)
}
}(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
length := fmt.Sprintf("%d", len(body))
mut.Lock()
defer mut.Unlock()
Database(link,length,d,l)
}
}
const (
LinkColor = "\033[1;34m%s\033[0m"
HelpColor = "\033[1;36m%s\033[0m"
BannerMColor = "\033[1;33m%s\033[0m"
BannerColor = "\033[1;31m%s\033[0m"
)
func main(){
s := flag.Bool("s",false,"silent mode (no banner)")
u := flag.Bool("u",false,"example of usage")
d := flag.Bool("d",false,"dont log the data")
w := flag.Bool("w",false,"without color (for windows user)")
l := flag.Bool("l",false,"return links without any tag (dont effect in log file)")
flag.Parse()
if *s == false && *w == true{
fmt.Printf("\n╔═╗┬ ┬┌─┐┌┐┌┌─┐┌─┐ ╔╦╗┌─┐┬ ┬┌─┐┬─┐\n║ ├─┤├─┤││││ ┬├┤ ║ │ ││││├┤ ├┬┘\n╚═╝┴ ┴┴ ┴┘└┘└─┘└─┘ ╩ └─┘└┴┘└─┘┴└─\nThe Cats : https://github.com/DC4ts\n\n")
}else if *s == false{
fmt.Printf(BannerColor,"\n╔═╗┬ ┬┌─┐┌┐┌┌─┐┌─┐ ╔╦╗┌─┐┬ ┬┌─┐┬─┐")
fmt.Printf(BannerMColor,"\n║ ├─┤├─┤││││ ┬├┤ ║ │ ││││├┤ ├┬┘\n")
fmt.Printf(BannerColor,"╚═╝┴ ┴┴ ┴┘└┘└─┘└─┘ ╩ └─┘└┴┘└─┘┴└─\n")
fmt.Printf("The Cats : ")
fmt.Printf(LinkColor,"https://github.com/DC4ts\n\n")
}
if *u == true && *w == true{
FileName := os.Args[0]
fmt.Printf("for list of urls:\n\tcat links.txt | %s\nfor single url:\n\techo \"https://example.com\" | %s\n",FileName,FileName)
}else if *u == true{
FileName := os.Args[0]
fmt.Printf(HelpColor,"for list of urls:\n\t")
fmt.Printf("cat links.txt | %s\n",FileName)
fmt.Printf(HelpColor,"for single url:\n\t")
fmt.Printf("echo \"https://example.com\" | %s\n",FileName)
}else{
if *d == false{
now := time.Now()
year := now.Year()
month := int(now.Month())
day := now.Day()
hour := now.Hour()
min := now.Minute()
name := fmt.Sprintf("%d-%d-%d-%d-%d.md",year,month,day,hour,min)
file, err := os.OpenFile(name, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666)
if err != nil {
log.Fatal(err)
}
log.SetOutput(file)
if *s == false{
fmt.Printf("result log file: %s\n",name)
}
}
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
scanner := bufio.NewScanner(os.Stdin)
var link string
for scanner.Scan(){
link = scanner.Text()
go Length(link,*d,*l)
wg.Add(1)
}
wg.Wait()
}
}