Knowledge Base
v5.11.0
Search this version
Knowledge Base
Knowledge Base
Configuration & Setup
Error & Troubleshooting
Testing & Upgrade
Title
Message
Create new category
What is the title of your new category?
Edit page index title
What is the title of the page index?
Edit category
What is the new title of your category?
Edit link
What is the new title and URL of your link?
How to send a file to ICAP server for testing the functionalities using the powershell script?
Copy Markdown
Open in ChatGPT
Open in Claude
Create a powershell script with the content below and save it as icap_win.ps1
TEXT
x
51
51
1
param (2
[string]$icapServer = "127.0.0.1", #ICAP server IP3
[int]$icapPort ="1344", # ICAP default port4
[string]$icapService = "/OMSScanReq-AV", # ICAP service name5
[string]$filePath = "" # Path to the file6
)7
8
# Read file content9
$fileContent = [System.IO.File]::ReadAllBytes($filePath)10
$fileSize = $fileContent.Length11
$chunkSize = [Convert]::ToString($fileSize, 16) # Convert size to hexadecimal12
13
# Define ICAP Headers14
$icapRequest = "REQMOD icap://$icapServer`:$icapPort$icapService ICAP/1.0`r`n"15
$icapRequest += "Host: $icapServer`r`n"16
$icapRequest += "User-Agent: PowerShell-ICAP-Client`r`n"17
$icapRequest += "Encapsulated: req-hdr=0, req-body=" + ($fileSize + 4) + "`r`n`r`n"18
19
# Define HTTP Encapsulation (Required by ICAP)20
$httpRequest = "POST /test.html HTTP/1.1`r`n"21
$httpRequest += "Host: example.com`r`n"22
$httpRequest += "Content-Length: $fileSize`r`n"23
$httpRequest += "Content-Type: application/octet-stream`r`n`r`n"24
25
# Properly format file content as chunked encoding26
$chunkedData = "$chunkSize`r`n"27
$chunkedData += [System.Text.Encoding]::UTF8.GetString($fileContent) + "`r`n"28
$chunkedData += "0`r`n`r`n" # End of chunk29
30
# Combine ICAP and HTTP requests31
$fullRequest = $icapRequest + $httpRequest + $chunkedData32
33
# Create a TCP socket to communicate with the ICAP server34
$tcpClient = New-Object System.Net.Sockets.TcpClient($icapServer, $icapPort)35
$stream = $tcpClient.GetStream()36
$writer = New-Object System.IO.StreamWriter($stream)37
$reader = New-Object System.IO.StreamReader($stream)38
39
# Send the properly formatted ICAP request40
$writer.Write($fullRequest)41
$writer.Flush()42
43
# Receive and display ICAP response44
$response = $reader.ReadToEnd()45
Write-Output "ICAP Server Response:`n$response"46
47
# Close the connection48
$writer.Close()49
$reader.Close()50
$stream.Close()51
$tcpClient.Close()Execute the script following the command
TEXT
1
1
1
.\icap_win.ps1 -icapServer <ICAP Server IP> -icapPort <ICAP Port> -filePath <Path to test file>Example:
TEXT
.\icap_win.ps1 -icapServer "127.0.0.1" -icapPort 1344 -filePath "D:\eicar.txt"If Further Assistance is required, please proceed to log a support case or chatting with our support engineer.
Type to search, ESC to discard
Type to search, ESC to discard
Type to search, ESC to discard
Last updated on
Was this page helpful?
Discard Changes
Do you want to discard your current changes and overwrite with the template?
Archive Synced Block
Message
Create new Template
What is this template's title?
Delete Template
Message
