From 427defea9953bfe8857ca8a1ebb0b7f24b292b0a Mon Sep 17 00:00:00 2001 From: Oleksii Shevchuk Date: Mon, 13 Mar 2017 23:19:43 +0200 Subject: [PATCH] psutil already have boot_time function, no need in separate module --- client/sources-linux/buildenv.sh | 4 ++-- client/sources/buildenv.sh | 4 ++-- pupy/network/lib/picocmd/picocmd.py | 26 +++++++++++++++++++++----- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/client/sources-linux/buildenv.sh b/client/sources-linux/buildenv.sh index d4d7fd35..73ddfa47 100755 --- a/client/sources-linux/buildenv.sh +++ b/client/sources-linux/buildenv.sh @@ -250,7 +250,7 @@ __EOF__ python -OO -m pip install six packaging appdirs python -OO -m pip install \ rpyc pycrypto pyaml rsa netaddr tinyec pyyaml ecdsa \ - paramiko uptime pylzma pydbus python-ptrace psutil scandir \ + paramiko pylzma pydbus python-ptrace psutil scandir \ scapy colorama pyOpenSSL \ --upgrade --no-binary :all: @@ -472,7 +472,7 @@ make install python -OO -m pip install six packaging appdirs python -OO -m pip install \ rpyc pycrypto pyaml rsa netaddr tinyec pyyaml ecdsa \ - paramiko uptime pylzma pydbus python-ptrace psutil scandir \ + paramiko pylzma pydbus python-ptrace psutil scandir \ scapy colorama pyOpenSSL \ --upgrade --no-binary :all: diff --git a/client/sources/buildenv.sh b/client/sources/buildenv.sh index 1ee985e5..680a115c 100755 --- a/client/sources/buildenv.sh +++ b/client/sources/buildenv.sh @@ -16,8 +16,8 @@ PYTHONVC="https://download.microsoft.com/download/7/9/6/796EF2E4-801B-4FC4-AB28- # PYWIN32="http://downloads.sourceforge.net/project/pywin32/pywin32/Build%20220/pywin32-220.win32-py2.7.exe" # PYWIN64="http://downloads.sourceforge.net/project/pywin32/pywin32/Build%20220/pywin32-220.win-amd64-py2.7.exe" -PACKAGES="rpyc pyaml rsa pefile image rsa netaddr win_inet_pton netaddr tinyec uptime pycrypto cryptography pypiwin32" -PACKAGES="$PACKAGES asyncoro mss pyaudio scapy pyOpenSSL colorama pyuv" +PACKAGES="rpyc pyaml rsa pefile image rsa netaddr win_inet_pton netaddr tinyec pycrypto cryptography pypiwin32" +PACKAGES="$PACKAGES mss pyaudio scapy pyOpenSSL colorama pyuv" BUILDENV=${1:-`pwd`/buildenv} diff --git a/pupy/network/lib/picocmd/picocmd.py b/pupy/network/lib/picocmd/picocmd.py index 379b8a9a..d49c051b 100644 --- a/pupy/network/lib/picocmd/picocmd.py +++ b/pupy/network/lib/picocmd/picocmd.py @@ -10,11 +10,11 @@ import time import datetime import platform import uuid -import uptime import urllib2 import urlparse import StringIO import socket +import psutil def from_bytes(bytes): return sum(ord(byte) * (256**i) for i, byte in enumerate(bytes)) @@ -199,7 +199,7 @@ class SystemInfo(Command): self.arch = arch or platform.machine() self.node = node or uuid.getnode() try: - self.boottime = boottime or uptime.boottime() + self.boottime = boottime or psutil.boot_time() except: self.boottime = datetime.datetime.fromtimestamp(0) @@ -256,9 +256,25 @@ class SystemInfo(Command): archid = (block >> 1) & 7 internet = bool(block & 1) node = from_bytes(node) - ip, boottime = struct.unpack('>II', rest) - boottime = datetime.datetime.fromtimestamp(boottime) - ip = netaddr.IPAddress(ip) + + ip = 0 + boottime = 0 + + try: + ip, boottime = struct.unpack('>II', rest) + + try: + boottime = datetime.datetime.fromtimestamp(boottime) + except: + pass + + try: + ip = netaddr.IPAddress(ip) + except: + pass + + except: + pass return SystemInfo( system=SystemInfo.well_known_os_names_decode[osid],