Coder Social home page Coder Social logo

Comments (2)

tkrebes avatar tkrebes commented on June 16, 2024

Hi,

The session that is opened is a System object. So, the network properties can be a bit confusing. You can access the primary ethernet adaptor properties via the system properties. For example,

def get_network_settings(target_name: str, username: str, password: str):
    nisystem = {}
    print("Trying to connect to target: " + target_name)
    with nisyscfg.Session(target=target_name, username=username, password=password) as session:
        print("Succesfully connected to target: " + str(session.resource.name))
        print("session.resource dir: " + str(dir(session)) + "\n\n")
        nisystem["serial_number"] = str(session.serial_number)
        nisystem["ip_address"] = str(session.ip_address)
        nisystem["subnet_mask"] = str(session.subnet_mask)
        nisystem["gateway"] = str(session.gateway)
        nisystem["dns_server"] = str(session.dns_server)
        print(nisystem)

However, the resource properties of the system do not contain the most of the network properties.

If you want to configure the network adaptors directly, use net interfaces returned by find_hardware(). The following example prints out a report similar to the network settings tab found in NI MAX:

import textwrap
import nisyscfg

def print_network_settings():
    with nisyscfg.Session() as session:
        print("Network Adapters")
        for resource in session.find_hardware():
            if nisyscfg.enums.ServiceType.LOCAL_NET_INTERFACE in resource.service_type:
                print("")
                print(textwrap.dedent(
                f"""
                    {resource.name}{' (Primary)' if resource.is_primary_adapter else ''}
                        Adapter Mode:         {resource.name}
                        MAC Address:          {resource.mac_address}
                        IPv4 Address Mode:    {repr(resource.tcp_ip_request_mode)}
                        IPv4 Address:         {resource.tcp_ip_v4_address}
                        Subnet Mask:          {resource.tcp_ip_v4_subnet}
                        Gateway:              {resource.tcp_ip_v4_gateway}
                        DNS Server:           {resource.tcp_ip_v4_dns_server}
                """).strip() )

from nisyscfg-python.

tkrebes avatar tkrebes commented on June 16, 2024

I assume the question has been answered.

from nisyscfg-python.

Related Issues (10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.