0

I have a code in Python that's supposed to take SMSs and scan them for viruses.

For that, I need to use Clamav antivirus engine (it also needs pyclam library but I have installed it). Now I am trying to run my code on pycharm but it gives me errors as if I did not install my ClamAv correctly. But I did exactly as the instructions in https://www.clamav.net/. I have Windows OS.

The code itself has no problem, 100% certain about that.

the code:

import pyclamd

def scan_sms_content(content):
    # Connect to the ClamAV daemon
    clamav = pyclamd.ClamdAgnostic()

    # Scan the content for viruses
    scan_result = clamav.scan_stream(content)

    # Check the scan result
    if scan_result is not None:
        if scan_result['stream'][content]['status'] == 'FOUND':
            virus_name = scan_result['stream'][content]['reason']
            print(f"Virus found: {virus_name}")
        else:
            print("No virus found.")
    else:
        print("Scan error.")

# sample sms database
sms_database = [
{
    'sender': '+1234567890',
    'content': 'Hello, how are you?',
    'timestamp': '2023-05-25 10:15:00'
},
{
    'sender': '+9876543210',
    'content': 'Meeting at 2 PM today.',
    'timestamp': '2023-05-25 11:30:00'
},
{
    'sender': '+5555555555',
    'content': 'URGENT: Please reply ASAP!',
    'timestamp': '2023-05-25 12:45:00'
},
{
    'sender': '+1234567890',
    'content': 'Hello, this is a test message with a potential virus!',
    'timestamp': '2023-05-25 15:30:00'
}
]

def process_sms(sms_data):
    # Extract the SMS content from the data
    sms_content = sms_data['content']

    # Perform virus scanning on the SMS content
    scan_sms_content(sms_content)

if __name__ == '__main__':
    # Process the sample SMS
    for sms in sms_database:
        process_sms(sms)

the error:

C:\Users\user\anaconda3\python.exe C:/Users/user/Downloads/main-1.py
Traceback (most recent call last):
  File "C:\Users\user\anaconda3\lib\site-packages\pyclamd\pyclamd.py", line 811, in ClamdAgnostic
    cd = ClamdUnixSocket()
  File "C:\Users\user\anaconda3\lib\site-packages\pyclamd\pyclamd.py", line 709, in __init__
    raise ConnectionError('Could not find clamd unix socket from /etc/clamav/clamd.conf or /etc/clamd.conf')
pyclamd.pyclamd.ConnectionError: Could not find clamd unix socket from /etc/clamav/clamd.conf or /etc/clamd.conf

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\user\anaconda3\lib\site-packages\pyclamd\pyclamd.py", line 793, in _init_socket
    self.clamd_socket.connect((self.host, self.port))
ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\user\anaconda3\lib\site-packages\pyclamd\pyclamd.py", line 815, in ClamdAgnostic
    cd = ClamdNetworkSocket()
  File "C:\Users\user\anaconda3\lib\site-packages\pyclamd\pyclamd.py", line 779, in __init__
    self._init_socket()
  File "C:\Users\user\anaconda3\lib\site-packages\pyclamd\pyclamd.py", line 795, in _init_socket
    raise ConnectionError('Could not reach clamd using network ({0}, {1})'.format(self.host, self.port))
pyclamd.pyclamd.ConnectionError: Could not reach clamd using network (127.0.0.1, 3310)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/Users/user/Downloads/main-1.py", line 54, in <module>
    process_sms(sms)
  File "C:/Users/user/Downloads/main-1.py", line 49, in process_sms
    scan_sms_content(sms_content)
  File "C:/Users/user/Downloads/main-1.py", line 5, in scan_sms_content
    clamav = pyclamd.ClamdAgnostic()
  File "C:\Users\user\anaconda3\lib\site-packages\pyclamd\pyclamd.py", line 817, in ClamdAgnostic
    raise ValueError("could not connect to clamd server either by unix or network socket")
ValueError: could not connect to clamd server either by unix or network socket

Process finished with exit code 1

halfer
  • 19,824
  • 17
  • 99
  • 186
Nov Joy
  • 11
  • 2

0 Answers0