Knowledge Base
v5.10.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
param (
[string]$icapServer = "127.0.0.1", #ICAP server IP
[int]$icapPort ="1344", # ICAP default port
[string]$icapService = "/OMSScanReq-AV", # ICAP service name
[string]$filePath = "" # Path to the file
)
# Read file content
$fileContent = [System.IO.File]::ReadAllBytes($filePath)
$fileSize = $fileContent.Length
$chunkSize = [Convert]::ToString($fileSize, 16) # Convert size to hexadecimal
# Define ICAP Headers
$icapRequest = "REQMOD icap://$icapServer`:$icapPort$icapService ICAP/1.0`r`n"
$icapRequest += "Host: $icapServer`r`n"
$icapRequest += "User-Agent: PowerShell-ICAP-Client`r`n"
$icapRequest += "Encapsulated: req-hdr=0, req-body=" + ($fileSize + 4) + "`r`n`r`n"
# Define HTTP Encapsulation (Required by ICAP)
$httpRequest = "POST /test.html HTTP/1.1`r`n"
$httpRequest += "Host: example.com`r`n"
$httpRequest += "Content-Length: $fileSize`r`n"
$httpRequest += "Content-Type: application/octet-stream`r`n`r`n"
# Properly format file content as chunked encoding
$chunkedData = "$chunkSize`r`n"
$chunkedData += [System.Text.Encoding]::UTF8.GetString($fileContent) + "`r`n"
$chunkedData += "0`r`n`r`n" # End of chunk
# Combine ICAP and HTTP requests
$fullRequest = $icapRequest + $httpRequest + $chunkedData
# Create a TCP socket to communicate with the ICAP server
$tcpClient = New-Object System.Net.Sockets.TcpClient($icapServer, $icapPort)
$stream = $tcpClient.GetStream()
$writer = New-Object System.IO.StreamWriter($stream)
$reader = New-Object System.IO.StreamReader($stream)
# Send the properly formatted ICAP request
$writer.Write($fullRequest)
$writer.Flush()
# Receive and display ICAP response
$response = $reader.ReadToEnd()
Write-Output "ICAP Server Response:`n$response"
# Close the connection
$writer.Close()
$reader.Close()
$stream.Close()
$tcpClient.Close()
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Execute the script following the command
.\icap_win.ps1 -icapServer <ICAP Server IP> -icapPort <ICAP Port> -filePath <Path to test file>
9
1
Example:
.\icap_win.ps1 -icapServer "127.0.0.1" -icapPort 1344 -filePath "D:\eicar.txt"
Support:
If Further Assistance is required, please proceed to log a support case or chatting with our support engineer.
Last updated on
Was this page helpful?
Next to read:
How to configure SMTP server with authentication under MetaDefender ICAP Server to send notification to M365?null
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