class NetworkDevice:
def __init__(self, ip_address, device_type):
self.ip_address = ip_address
self.device_type = device_type
def get_details(self):
return f"Device Type: {self.device_type}, IP Address: {self.ip_address}"
def connect_to_device(device):
print(f"Attempting to connect to {device.device_type} at {device.ip_address}...")
# Simulate connection logic
is_connected = True # In a real scenario, this would involve more complex logic
if is_connected:
print(f"Successfully connected to {device.ip_address}!")
else:
print(f"Failed to connect to {device.ip_address}.")
# Creating instances of NetworkDevice
router = NetworkDevice("192.168.1.1", "Router")
switch = NetworkDevice("192.168.1.2", "Switch")
# Displaying device details
print(router.get_details())
print(switch.get_details())
# Connecting to devices
connect_to_device(router)
connect_to_device(switch)