Python Forum
using paramiko to see resualt
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
using paramiko to see resualt
#4
Answer to wrong topic or the op has changed something?
I don't know what happened :-D


The answer is related to: How to get the IP-Address from Windows.


The easiest approach to obtain the IP-Address is:
import socket


def get_ip():
    return socket.gethostbyname(socket.gethostname())


print(get_ip())
pexpect does not support Windows.
You could use wexpect.

I don't know if this works. I think the better approach is to use subprocess if you want to parse it by yourself.

Easier is to use netifaces.
But this does not work out of the box. A compiler is required.
You could download an unofficial compiled binary here: https://www.lfd.uci.edu/~gohlke/pythonlibs/#netifaces
This is actually (2022/12) only precompiled for Python 3.4 - 3.9

Much easier and platform independent is psutil.
import socket

import psutil


def get_ipv4():
    result = []
    for name, properties in psutil.net_if_addrs().items():
        for property in properties:
            if property.family == socket.AF_INET and property.ptp is None:
                result.append((name, property.address))

    return result


if __name__ == "__main__":
    for name, ip in get_ipv4():
        print(name, "->", ip)
The property.ptp is None if it is not a VPN connection or something else ptp based.
The names of the interfaces are not unique, and they also depend on language settings.

A network interface card could have more than one ip. This is why properties is a list. The objects in properties (the values of the resulting dict) are custom objects, where you can access the attributes like address, broadcast, .. etc.

To get more details if the interface is wireless or not, pywin32 or ctypes must be used.
If your Windows Desktop has only one NIC, you're lucky and do not require this detail.
If you know the name of the interface, you could filter for it. But then this code does not work, if you change the name.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Messages In This Thread
using paramiko to see resualt - by korenron - Dec-06-2022, 09:36 AM
RE: using paramiko to see resualt - by Gribouillis - Dec-06-2022, 09:41 AM
RE: using paramiko to see resualt - by korenron - Dec-06-2022, 09:49 AM
RE: using pexpect on windows - by DeaD_EyE - Dec-06-2022, 10:25 AM
RE: using paramiko to see resualt - by korenron - Dec-06-2022, 10:28 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020