-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkis5.ps1
55 lines (45 loc) · 1.94 KB
/
kis5.ps1
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
$start_time = Get-Date
function Get-KIS-parts ( $search , $URL , $a ) {
$urlHost = iwr -Uri $URL
$Path_regex = '.*(kis[^"<]+)'
#$File_regex = '.*(kis.*?en_\d+\.exe)'
$File_regex = '(?:kis)[\d\.]{3,}(?:.en_)\d{5,}.exe'
$cpt=1
$resu=@{}
$urlHost.ParsedHtml.getElementsByTagname("a") |%{
if ($_.id -eq $null){ $_.id="data$cpt";$cpt++}
$resu[$($_.id)]=$_.$search
#Write-Host $_.$search
if (( $a -eq '0' ) -and ( $_.$search -match $Path_regex )) {
$test = $_.$search
}
if (( $a -eq '1' ) -and ( $_.$search -match $File_regex )) {
Write-Host head ($URL+'/'+$_.$search)
$response = ( iwr ( $URL+'\'+$_.$search ) ).headers
$file_size = (($response['content-length'] -ge '2422304'))
if (( $_.$search -match '.exe' ) -and ( $file_size -ne 'True') ) {
Write-Host fl -$file_size-
$test = $_.$search
Write-Host test -$test-
}
}
}
return $test
}
$urlHost = 'http://products.kaspersky-labs.com/english/homeuser'
$urlPath = ( Get-KIS-parts -search "innerHTML" -URL $urlHost -a 0 )
Write-Host outside urlpath - $urlPath -
$myURL = $urlHost + '/' + $urlPath
Write-Host myurl -$myURL-
$urlFile = ( Get-KIS-parts -search "innerHTML" -URL $myURL -a 1 )
Write-Host outside urlfile -$urlFile-
$url = $urlHost+'/'+$urlPath+'/'+$urlFile
Write-Host outside url -$url-
$res = $urlFile -split('_')
$revision = $res[1] -replace('.exe','')
Write-Host outside revision -$revision-
$vers = $urlFile -match('[\d+\.]{3,}(?=en_)') # this (?=en_) is not needed to get the number we need
#$vers = $urlFile -match('(?<=en_)[\d]{5,\}')
$version = $matches[0]
Write-Host outside version -$version-
Write-host "Time taken: $((Get-Date).Subtract($start_time).Seconds) second(s)"