def _attempt_connection(self, net2_server, uid, pwd): """ Attempt connection to the Net2 Server. Returns a tuple (connected, net2) """ print("[NET2] Attempting to establish connection to Net2 Server on {0} (Operator ID: {1})".format( net2_server, uid)) with Net2XS(net2_server) as net2: try: net2.authenticate(uid, pwd) print("[NET2] Connection Established.") self.connection_status = self.CONNECTED self.api = net2 self.connected = True self._connect_thread_complete() except Net2XSException as exception: print("[NET2] Connection Failed.") print("[NET2] {0}".format(exception)) self.connection_status = self.DISCONNECTED self.connected = False self.api = False self._connect_thread_complete() except Exception as exception: print("[NET2] An unhandled exception occured during connection.") print("[NET2] {0}".format(exception)) self.connection_status = self.DISCONNECTED self.connected = False self.api = False self._connect_thread_complete()
""" Sample script to fetch all access levels """ from Net2Scripting import init_logging from Net2Scripting.net2xs import Net2XS # Operator id 0 is System Engineer OPERATOR_ID = 0 # Default Net2 password OPERATOR_PWD = "net2" # When running on the machine where Net2 is installed NET2_SERVER = "localhost" if __name__ == "__main__": # Init log4net init_logging() with Net2XS(NET2_SERVER) as net2: # Authenticate net2.authenticate(OPERATOR_ID, OPERATOR_PWD) # Show all access levels and their details for al in net2.get_py_access_levels(): print(al)
""" Sample script to fetch all cards """ from Net2Scripting import init_logging from Net2Scripting.net2xs import Net2XS # Operator id 0 is System Engineer OPERATOR_ID = 0 # Default Net2 password OPERATOR_PWD = "net2" # When running on the machine where Net2 is installed NET2_SERVER = "localhost" if __name__ == "__main__": # Init log4net init_logging() with Net2XS(NET2_SERVER) as net2: # Authenticate net2.authenticate(OPERATOR_ID, OPERATOR_PWD) # Obtain all Net2 cards print(Net2XS.dataset_to_str(net2.get_cards()))