deno.land / x / o_url@0.3 / O_url.module.js

O_url.module.js
نووسراو ببینە
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
import {O_folder_file} from "https://deno.land/x/o_folder_file@0.3/O_folder_file.module.js"class O_url{
constructor( s ){ // check if protocol
// |-------------------- Schema-spezifischer Teil ---------------------| // https://maxmuster:geheim@www.example.com:8080/index.html?p1=A&p2=B#ressource // \___/ \_______/ \____/ \_____________/ \__/\_________/ \_______/ \_______/ // | | | | | | | | // Schema+ Benutzer Kennwort Host Port Pfad Query Fragment // ⁺ (hier gleich Netzwerkprotokoll)

// file:///verzeichnis/unterverzeichnis/datei // \__/ \___________________________________/ // | | // Schema | // Pfad zu einer lokalen Datei im Dateisystem des Rechners, der den URL interpretiert this.o_URL = new URL(s) this.s_protocol = this.o_URL.protocol.replaceAll(":", "") this.s_schema = this.s_protocol this.s_username = this.o_URL.username this.s_password = this.o_URL.password this.s_password = this.o_URL.password this.s_hostname = this.o_URL.hostname this.s_port = this.o_URL.port this.n_port = parseInt(this.o_URL.port) this.s_domainname = this.o_URL.hostname this.s_query = this.o_URL.search this.s_fragment = this.o_URL.hash this.s_ipv4 = '' this.s_ipv6 = '' this.a_s_ip = [] this.a_s_ipv4 = [] this.a_s_ipv6 = [] this.o_folder_file = new O_folder_file(this.o_URL.pathname) this.s_path = this.o_URL.pathname this.o_geolocation = null

var s_domainname_trimmed = this.s_domainname.trim() if( s_domainname_trimmed.indexOf('[') == 0 && s_domainname_trimmed.indexOf(']') == (s_domainname_trimmed.length-1) ){ var s_domainname_trimmed = s_domainname_trimmed.splice(1, s_domainname_trimmed.length-1); this.s_ipv6 = s_domainname_trimmed // var a_s_domainname_part = s_domainname_trimmed.split(":") // 2606:4700:3033::ac43:b77f }
if(this.f_b_ipv4(this.s_domainname)){ console.log(this.s_domainname) console.log(this.s_domainname) console.log(this.s_domainname) console.log(this.s_domainname) console.log(this.s_domainname) console.log(this.s_domainname) this.s_ipv4 = this.s_domainname }

}
get s(){ return this._s } set s(value){ this._s = value this.f_update_all() } async f_update_o_geolocation(){ return new Promise( async (f_resolve) => {
var s_ipv4 = this.s_ipv4 if(s_ipv4 == ''){ await this.f_update_a_s_ip() var s_ipv4 = this.s_ipv4 } console.log(this.s_ipv4) // this.o_geolocation = await (await fetch("https://"+s_ipv4)).read(); const s_url = `https://ipinfo.io/${s_ipv4}` console.log(s_url) var s_o_geolocation = await ( await ( fetch( s_url, { headers: { 'Accept': 'application/json'}, } ) ) ).text(); this.o_geolocation = JSON.parse(s_o_geolocation) f_resolve() }) // var s_url = `curl ipinfo.io // this.o_ipinfo = Deno.run('curl ') }
async f_update_a_s_ip(){ return new Promise(async (f_resolve)=>{
var a_s_ip = await this.f_a_s_ip_by_s_domainname(this.s_domainname) this.a_s_ipv4 = [] this.a_s_ipv6 = [] for(var n_i in a_s_ip){ var s_ip = a_s_ip[n_i] if(this.f_b_ipv4(s_ip)){ this.a_s_ipv4.push(s_ip) this.s_ipv4 = s_ip }else{ this.a_s_ipv6.push(s_ip) this.s_ipv6 = s_ip } } f_resolve() }) }
async f_a_s_ip_by_s_domainname(s_domainname){ return new Promise(async (f_resolve) => {
const o_process = Deno.run( { cmd:['nslookup', s_domainname], stdout: "piped", stderr: "piped", } ) const { n_code } = await o_process.status(); const raw_output = await o_process.output(); const raw_error_output = await o_process.stderrOutput(); await o_process.close() // const raw_output_err = await o_process.sdterrOutput(); var a_s_address = []
const s_text = new TextDecoder().decode(raw_output); const a_s_line = s_text.split('\n'); const s_search_name = "Name:" const s_search_address = "Address:" var b_search_name = false var b_search_address = false for(var n_i in a_s_line){ var s_line = a_s_line[n_i] if(s_line.indexOf(s_search_name) == 0){ b_search_name = true continue } if(b_search_name && s_line.indexOf(s_search_address) == 0){ a_s_address.push(s_line.slice(s_search_address.length).trim()) } b_search_address = false b_search_name = false }

f_resolve(a_s_address)
}) } f_b_ipv4(s){ var a_n = s.trim().split('.') var self = this var a_n_filtered = a_n.filter(n => self.f_b_string_is_numeric(n)) // console.log(a_n_filtered) if(a_n.length == 4 && a_n_filtered.length == 4){ return true } return false } f_b_string_is_numeric(s){ return /^-?\d+$/.test(s); }

}
export {O_url}
o_url

Version Info

Tagged at
a year ago

External Dependencies

1 external dependency