#pip herunterladen
curl https://bootstrap.pypa.io/get-pip.py --output get-pip.py
#pip installieren
python2 get-pip.py
#und anzeigen lassen obs funktioniert hat.
pip2 --version
#ausgabe
pip 20.0.2 from /usr/local/lib/python2.7/dist-packages/pip (python 2.7)
NO-IP Account-Renew Script #190312
host_id=66xxxxxx [OK]
host_id=69xxxxxx [OK]
host_id=69xxxxxx [OK]
sudo apt-get install python-mechanize
root@hp-server:~# apt-get install python-mechanize
Paketlisten werden gelesen... Fertig
Abhängigkeitsbaum wird aufgebaut.
Statusinformationen werden eingelesen.... Fertig
E: Paket python-mechanize kann nicht gefunden werden.
Was meinst du damit?die Version ist von meiner Seite aus schon lange EOL.
pip3 install mechanicalsoup
#!/usr/bin/env python
# -*- coding: utf-8 -*-
### *|--------------------------------|* ###
### *| NO-IP Account-Renew Script 1.0 |* ###
### *| (c) by DarkStarXxX @ DEB |* ###
### *|--------------------------------|* ###
# Modifiziert von MegaV0lt @ DEB
# Modifiziert von SLASH @ DEB
# Modifiziert von bl0w @DEB
VERSION=201208
# Wichtiger Hinweis: Externe Konfiguration
# Die Login-Daten für No-IP und eMail können aus einer externen Datei, welche in
# der Variable "CONFIG_FILE" definiert werden muss gelesen werden.
# Besonderheit: Die Datei im Dateisystem muss die Endung ".py" haben.
# Bitte dort die Daten eintragen (Im gleichen Verzeichnis wie das Skript!)
CONFIG_FILE = "" # Ohne .py (Im gleichen Verzeichnis wie das Skript!)
# Kann abgeschaltet werden, in dem man CONFIG_FILE = "" setzt. In dem Fall die
# Variablen hier ausfüllen!
USERNAME = "" # No-IP Benutzername
PASSWORD = "" # No-IP Passwort
FROMADRESS = "" # eMail-Sender
TOADRESS = "" # eMail-Empfänger
SMTPSERVER = "" # SMTP-Serveradresse ("" zum deaktivieren)
SMTPPORT = "" # SMTP-Port (Z. B. 25)
SMTPPASS = "" # Server verlangt Autentification ("" zum deaktivieren)
# Vorgaben
LOG_FILE = "" # Kein Log, wenn nächste Zeile auskommentiert ist
#LOG_FILE = "/var/log/NOIP_renew.log" # Dateiname wird auch für die eMail verwendet
MAIL_SUBJECT = "NO-IP Account Updater" # Betreff der Status eMail
MAIL_BODY = "NO-IP Account Updater Service updated your NO-IP Account for another 30 days.\nPlease check the attached Logfile\n\n" # Text in der eMail
HOST_URL = "https://www.noip.com/members/dns/"
RESULT_STR = []
import importlib
import mechanicalsoup
import time
import ssl
import re
if hasattr(ssl, '_create_unverified_context'):
ssl._create_default_https_context = ssl._create_unverified_context
# Funktion: update_host - Für jeden Host "Modify" klicken
def update_host(str_host, br):
global RESULT_STR
br.select_form(nr=00)
br.submit_selected()
# Check if OK
if LOG_FILE:
ts = time.strftime("%d.%m.%Y %H:%M:%S") # Zeitstempel für das Log (19.10.2016 12:51:30)
f1 = open(LOG_FILE, 'a+')
host_id = after(str_host, "?") # Alle Zeichen nach dem ?
if br.response().read().find("Update will be applied") >= 0:
if LOG_FILE: print >> f1,ts,host_id + " [OK]" # Ausgabe in das Log
print(host_id + " [OK]") # Ausgabe auf der Konsole (und cron)
RESULT_STR.append(host_id + " [OK]") # Für die eMail
else:
if LOG_FILE: print >> f1,ts,host_id + " [FAILED]"
print(host_id + " [FAILED]")
RESULT_STR.append(host_id + " [FAILED]")
return
#Funktion: after - Liefert Zeichenkette nach Zeichen a
def after(value, a):
# Find and validate first part
pos_a = value.rfind(a)
if pos_a == -1: return value # Nicht gefunden: Ganzer Wert zurück!
# Returns chars after the found string.
adjusted_pos_a = pos_a + len(a)
if adjusted_pos_a >= len(value): return ""
return value[adjusted_pos_a:]
# Browser options
br = mechanicalsoup.StatefulBrowser(
soup_config={'features': 'lxml'}, # Use the lxml HTML parser
raise_on_404=True,
user_agent='Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.2228.0 Safari/537.36',
)
### Start
print("NO-IP Account-Renew Script #%s" % VERSION)
if CONFIG_FILE:
print('Lade Konfiguration aus ' + CONFIG_FILE + '.py')
myconf = importlib.import_module(CONFIG_FILE, package=None)
USERNAME = myconf.USERNAME ; PASSWORD = myconf.PASSWORD
FROMADRESS = myconf.FROMADRESS ; TOADRESS = myconf.TOADRESS
SMTPSERVER = myconf.SMTPSERVER ; SMTPPORT = myconf.SMTPPORT
SMTPPASS = myconf.SMTPPASS
# Prüfen, ob USERNAME und PASSWORT konfiguriert sind
if not USERNAME:
print('FEHLER: USERNAME ist nicht konfiguriert!') ; quit()
if not PASSWORD:
print('FEHLER: PASSWORD ist nicht konfiguriert!') ; quit()
# Seite öffnen
br.open(HOST_URL)
# Login
br.select_form()
br["username"] = USERNAME
br["password"] = PASSWORD
br.submit_selected()
# Links in Array speichern
mylink = [] # Leeres Array
for link in br.links():
if link.text == 'Modify': mylink += [link]
# Links klicken und Updaten
for link in mylink:
target = link.attrs['href']
br.open_relative(target)
update_host(link.url, br)
####### SMTP Section ############
if not SMTPSERVER: quit() # Nur wenn SMTPSERVER gesetzt ist
import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
from email.MIMEBase import MIMEBase
from email import encoders
msg = MIMEMultipart()
msg['From'] = FROMADRESS ; msg['To'] = TOADRESS
msg['Subject'] = MAIL_SUBJECT
body = MAIL_BODY
for var in RESULT_STR:
body = str(body) + str(var) + "\n"
msg.attach(MIMEText(body, 'plain'))
if LOG_FILE:
filename = after(LOG_FILE, "/") # Dateiname ohne Pfad
attachment = open(LOG_FILE, "rb")
part = MIMEBase('application', 'octet-stream')
part.set_payload((attachment).read())
encoders.encode_base64(part)
part.add_header('Content-Disposition', "attachment; filename= %s" % filename)
msg.attach(part)
# Example: Server Address and TCP Port - Exmaple: '192.168.1.1' , 25
server = smtplib.SMTP(SMTPSERVER, SMTPPORT)
server.starttls()
# Server verlangt Autentification (Nur wenn SMTPPASS gesetzt ist)
if SMTPPASS: server.login(FROMADRESS, SMTPPASS)
text = msg.as_string()
server.sendmail(FROMADRESS, TOADRESS, text)
server.quit()
root@hp-server:/usr/local/bin# pip3 install mechanicalsoup
Collecting mechanicalsoup
Downloading MechanicalSoup-0.12.0-py2.py3-none-any.whl (18 kB)
Requirement already satisfied: requests>=2.0 in /usr/lib/python3/dist-packages (from mechanicalsoup) (2.22.0)
Collecting beautifulsoup4>=4.4
Downloading beautifulsoup4-4.9.3-py3-none-any.whl (115 kB)
|████████████████████████████████| 115 kB 8.4 MB/s
Requirement already satisfied: six>=1.4 in /usr/lib/python3/dist-packages (from mechanicalsoup) (1.14.0)
Collecting lxml
Downloading lxml-4.6.2-cp38-cp38-manylinux1_x86_64.whl (5.4 MB)
|████████████████████████████████| 5.4 MB 13.2 MB/s
Collecting soupsieve>1.2; python_version >= "3.0"
Downloading soupsieve-2.0.1-py3-none-any.whl (32 kB)
Installing collected packages: soupsieve, beautifulsoup4, lxml, mechanicalsoup
Successfully installed beautifulsoup4-4.9.3 lxml-4.6.2 mechanicalsoup-0.12.0 soupsieve-2.0.1
root@hp-server:/usr/local/bin# ./noip-account-renew
Traceback (most recent call last):
File "./noip-account-renew", line 37, in <module>
import mechanicalsoup
ImportError: No module named mechanicalsoup
Please wait a moment while I gather a list of all available modules...
BaseHTTPServer _pyio getopt rlcompleter
Bastion _random getpass robotparser
CDROM _sha gettext runpy
CGIHTTPServer _sha256 glob sched
Canvas _sha512 grp select
ConfigParser _socket gzip sets
Cookie _sqlite3 hashlib sgmllib
DLFCN _sre heapq sha
DbgPlugInDiggers _ssl hmac shelve
Dialog _strptime hotshot shlex
DocXMLRPCServer _struct htmlentitydefs shutil
FileDialog _symtable htmllib signal
FixTk _sysconfigdata httplib site
HTMLParser _sysconfigdata_nd ihooks sitecustomize
IN _testcapi imaplib smtpd
MimeWriter _threading_local imghdr smtplib
Queue _warnings imp sndhdr
ScrolledText _weakref importlib socket
SimpleDialog _weakrefset imputil spwd
SimpleHTTPServer abc inspect sqlite3
SimpleXMLRPCServer aifc io sre
SocketServer antigravity itertools sre_compile
StringIO anydbm json sre_constants
TYPES argparse keyword sre_parse
Tix array lib2to3 ssl
Tkconstants ast libvboxjxpcom stat
Tkdnd asynchat linecache statvfs
Tkinter asyncore linuxaudiodev string
UICommon atexit locale stringold
UserDict audiodev logging stringprep
UserList audioop lsb_release strop
UserString base64 macpath struct
VBoxAuth bdb macurl2path subprocess
VBoxAuthSimple binascii mailbox sunau
VBoxDD binhex mailcap sunaudio
VBoxDD2 bisect markupbase symbol
VBoxDDU bsddb marshal symtable
VBoxDbg bz2 math sys
VBoxDragAndDropSvc cPickle md5 sysconfig
VBoxGuestControlSvc cProfile mhlib syslog
VBoxGuestPropSvc cStringIO mimetools tabnanny
VBoxHeadless calendar mimetypes tarfile
VBoxHostChannel cgi mimify telnetlib
VBoxKeyboard cgitb mmap tempfile
VBoxNetDHCP chunk modulefinder termios
VBoxNetNAT cmath multifile test
VBoxPython cmd multiprocessing textwrap
VBoxPython2_7 code mutex this
VBoxPython3_7m codecs netrc thread
VBoxRT codeop new threading
VBoxSDL collections nis time
VBoxSVGA3D colorsys nntplib timeit
VBoxSharedClipboard commands ntpath tkColorChooser
VBoxSharedFolders compileall nturl2path tkCommonDialog
VBoxVMM compiler numbers tkFileDialog
VBoxXPCOM contextlib opcode tkFont
VBoxXPCOMC cookielib operator tkMessageBox
VirtualBoxVM copy optparse tkSimpleDialog
_LWPCookieJar copy_reg os toaiff
_MozillaCookieJar crypt os2emxpath token
__builtin__ csv ossaudiodev tokenize
__future__ ctypes parser trace
_abcoll curses pdb traceback
_ast datetime pickle ttk
_bisect dbhash pickletools tty
_bsddb dbm pipes turtle
_codecs decimal pkgutil types
_codecs_cn difflib platform unicodedata
_codecs_hk dircache plistlib unittest
_codecs_iso2022 dis popen2 urllib
_codecs_jp distutils poplib urllib2
_codecs_kr doctest posix urlparse
_codecs_tw dumbdbm posixfile user
_collections dummy_thread posixpath uu
_csv dummy_threading pprint uuid
_ctypes email profile vboxapi
_ctypes_test encodings pstats vboxshell
_curses ensurepip pty warnings
_curses_panel errno pwd wave
_elementtree exceptions py_compile weakref
_functools fcntl pyclbr webbrowser
_hashlib filecmp pydoc whichdb
_heapq fileinput pydoc_data wsgiref
_hotshot fnmatch pyexpat xdrlib
_io formatter quopri xml
_json fpformat random xmllib
_locale fractions re xmlrpclib
_lsprof ftplib readline xxsubtype
_md5 functools repr zipfile
_multibytecodec future_builtins resource zipimport
_multiprocessing gc rexec zlib
_osx_support genericpath rfc822
pip install mechanicalsoup
which python
pip --version
pip install mechanize
oder
python -m pip install mechanize
pip install mechanicalsoup
which python
pip --version
pip install mechanize
oder
python -m pip install mechanize
root@hp-server:~# apt install python-pip
Paketlisten werden gelesen... Fertig
Abhängigkeitsbaum wird aufgebaut.
Statusinformationen werden eingelesen.... Fertig
E: Paket python-pip kann nicht gefunden werden.
#pip herunterladen
curl https://bootstrap.pypa.io/get-pip.py --output get-pip.py
#pip installieren
python2 get-pip.py
#und anzeigen lassen obs funktioniert hat.
pip2 --version
#ausgabe
pip 20.0.2 from /usr/local/lib/python2.7/dist-packages/pip (python 2.7)
NO-IP Account-Renew Script #190312
host_id=66xxxxxx [OK]
host_id=69xxxxxx [OK]
host_id=69xxxxxx [OK]
Wir verwenden Cookies und ähnliche Technologien für folgende Zwecke:
Akzeptieren Sie Cookies und diese Technologien?
Wir verwenden Cookies und ähnliche Technologien für folgende Zwecke:
Akzeptieren Sie Cookies und diese Technologien?