Skip to content

Tools

Snmpscan

ScanResult dataclass

Snmpscan's result

Source code in pvi\Snmpscan.py
31
32
33
34
35
36
37
38
39
40
@dataclass
class ScanResult:
    """Snmpscan's result
    """
    target : str # CPU type
    AR : str # Automation Runtime Version
    ip : str # IP Address
    subnet : str # Subnet mask
    serial_number : str # hardware serial number
    status: str # Automation Runtime status

snmp_scan()

scans for CPUs with SNMP protocol activated

Returns:

Type Description
List[ScanResult]

list with scan results, namedtuple 'ScanResult'

Source code in pvi\Snmpscan.py
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
def snmp_scan()->List[ScanResult] :
    """scans for CPUs with SNMP protocol activated

    Returns:
        list with scan results, namedtuple 'ScanResult'
    """    

    global pviConnection, cpu_list, device

    device.errorChanged = deviceErrorChanged
    cpu_list.clear()
    pviConnection.start() 
    return cpu_list   

Anslscan

ScanResult dataclass

Anslscan's result

Source code in pvi\Anslscan.py
42
43
44
45
46
47
48
49
@dataclass
class ScanResult:
    """Anslscan's result
    """    
    target: str # CPU type
    AR: str  # Automation Runtime Version
    ip: str #IP address
    status: str # Automation Runtime status

ansl_scan(network)

Scan for CPU with ANSL protocol activated

Parameters:

Name Type Description Default
network

IP4 network, e.g. 192.168.100.0/24 or 192.168.100.0/255.255.255.0

required

Returns:

Type Description
List[ScanResult]

list with scan results, namedtuple('ScanResult', ['target','AR', 'ip','status'])

Source code in pvi\Anslscan.py
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
def ansl_scan( network : ipaddress.IPv4Network )->List[ScanResult] :
    """Scan for CPU with ANSL protocol activated

    Args:
        network : IP4 network, e.g. 192.168.100.0/24 or 192.168.100.0/255.255.255.0

    Returns:
        list with scan results, namedtuple('ScanResult', ['target','AR', 'ip','status'])
    """    
    global cpu_list, network_to_scan

    pviConnection = Connection() # start a Pvi connection
    line = Line( pviConnection.root, 'LNANSL', CD='LNANSL')
    device = Device( line, 'TCP', CD='/IF=TcpIp' )
    network_to_scan = ipaddress.IPv4Network('127.0.0.1')
    cpu_list = list()

    def objectsArranged() -> None:       
        # Check servers simultaneously using ThreadPoolExecutor
        with ThreadPoolExecutor(max_workers=MAX_WORKERS) as executor:
            results = executor.map(lambda host: check_server(str(host)), network_to_scan.hosts() ) # type: ignore
            results = [item for item in results if item is not None]

        # connect to all CPUs found with PVI to get further information
        for result in results:          
            cpu = Cpu( device, 'newCpu', CD='/IP=' + result )
            cpu.ip_address = result # type: ignore ,add dynamic member for IP address
            cpu.checked = False # type: ignore , add dynamic member for 'checked' state
            cpu.errorChanged = cast( Callable[[PviObject,int],None], cpu_error_change )
            while not(cpu.checked): # type: ignore
                pviConnection.doEvents()
            cpu.kill()
            del cpu

        device.kill()
        line.kill()
        pviConnection.stop()

    network_to_scan = network
    pviConnection.objectsArranged = objectsArranged
    pviConnection.start() 

    return cpu_list   

Inascan

ScanResult dataclass

Inascan's result

Source code in pvi\Inascan.py
39
40
41
42
43
44
45
46
47
@dataclass
class ScanResult: 
    """Inascan's result
    """
    target: str  # CPU type
    AR: str  # Automation Runtime Version
    ip: str  # IP address
    node: str  # INA node number
    status: str  # Automation Runtime status

ina_scan(network)

Scan for CPU with INA2000 protocol activated

Parameters:

Name Type Description Default
network

IP4 network, e.g. 192.168.100.0/24 or 192.168.100.0/255.255.255.0

required

Returns:

Type Description
List[ScanResult]

list with scan results, namedtuple('ScanResult', ['target','AR', 'ip', 'node', 'status'])

Source code in pvi\Inascan.py
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
def ina_scan( network : ipaddress.IPv4Network )->List[ScanResult] :
    """Scan for CPU with INA2000 protocol activated

    Args:
        network : IP4 network, e.g. 192.168.100.0/24 or 192.168.100.0/255.255.255.0

    Returns:
        list with scan results, namedtuple('ScanResult', ['target','AR', 'ip', 'node', 'status'])
    """    
    global pviConnection, ip, cpu_list, network_to_scan
    cpu_list.clear()
    network_to_scan = network
    pviConnection.objectsArranged = objectsArranged
    pviConnection.start() 
    return cpu_list