在代理

时间:2016-04-18 19:24:32

标签: powershell proxy

我正在尝试查看/测试代理上的阻止类别。我写了一个有效的脚本,但是我得到了预期的结果,但是当我尝试使用凭据时,我得到了相同的结果。我正在使用的凭据适用于应该可以访问通常为常规用户阻止的某些类别的用户,但我获得的结果与普通用户相同。我已经仔细检查过用户是排除组的一部分,但似乎没有工作。例如,没有信用卡,Facebook等网站被阻止,但应该允许使用信用卡。当我使用信用卡在机器上手动设置代理时,我能够导航到Facebook,所以我知道信用卡的工作。我只是不知道如何让他们在剧本中工作。

#Setting proxies 
$prox1 = "Proxy1"
$prox2 = "Proxy2"

#Setting Credentials
$Users = "Username"
$pass = "Passowrd"

foreach($User in $Users){

$file =  $User + ".csv"
echo "Category`tProxy1`tProxy2`tEqual`tSite" >> $file

#Setting categories to check
$cats = "Bluecoat Test Pages"
#Setting credentials
$Password = ConvertTo-SecureString $pass -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential $User, $Password 

#For each category test using both proxies          
foreach($cat in $cats)  {

#Creating new system object proxy and setting it to use first proxy
    $proxy = new-object System.Net.WebProxy($prox1) 
#Setting credentials
    $proxy.credentials = $cred
#Creating new web client
    $WebClient = new-object System.Net.WebClient
#Making web client use set proxy
    $WebClient.proxy = $proxy


#splits site from category name
    $cat = $cat.split("-")
    $cat_name = $cat[0]
    $site = $cat[1]

    write-host $cat_name
#tries to download site html    
    try{                                                                                      
        $html1=$WebClient.downloadstring($site)                              
    }   
#if exception then wasnt able to download html and was blocked  
    catch [system.exception]{
        write-host "`tBlocked -" $prox1 -ForegroundColor Red
        $rp1 = "Blocked"
    }
#if html has content then site was accessible and is allowed
    if($html1){ 
        write-host "`tAllowed -"  $prox1 -ForegroundColor Cyan
        $rp1 = "Allowed"        
    }

#Above process repeats for second proxy.

    if($rp1 -eq $rp2){
        $equal = "TRUE"
    }
    else{
        $equal = "FALSE"
    }
    echo "$cat_name`t$rp1`t$rp2`t$equal`t$site" >> $file

    $html1 = ""
    $html2 = ""
    $rp1 = ""
    $rp2 = ""
}
Start-Sleep -s 10

0 个答案:

没有答案