Форум сайта python.su
class SOCKS_IMAP4_SSL(imaplib.IMAP4_SSL): def __init__(self, host, port = imaplib.IMAP4_SSL_PORT, proxy_type = None, proxy = None,): self.proxy = proxy self.proxy_type = proxy_type imaplib.IMAP4_SSL.__init__(self, host, port) def open(self, host, port = imaplib.IMAP4_SSL_PORT): self.host = host self.port = port if self.proxy and self.proxy_type: proxy_ip, proxy_port = self.proxy.split(':') self.sock = socks.create_connection((host, port), self.proxy_type, proxy_ip, int(proxy_port)) else: self.sock = socket.create_connection((host, port)) self.sslobj = ssl.wrap_socket(self.sock, self.keyfile, self.certfile) self.file = self.sslobj.makefile('rb')
SSLEOFError: EOF occurred in violation of protocol (_ssl.c:590)
import telnetlib import time def main(): HOST = "172.17.53.30".encode("utf-8") user = "user\r".encode("utf-8") password = "passw\r".encode("utf-8") tn = telnetlib.Telnet(HOST,23,5) # Логинимся print 'login', tn.read_until("Username: ") tn.write(user.encode("utf-8") ) print 'ok\npass', tn.read_until("Password: ") tn.write(password.encode("utf-8") ) print 'ok' # Читаем результат, посылаем команду time.sleep(3) tn.write("telnet 127.0.0.1 8888\r") time.sleep(3) tn.read_until("BNG_Router# ") tn.write("show sessions all include IPoE\r") tn.write("exit\r") print tn.read_all() main()
You are using pip version 7.1.0, however version 8.1.2 is available. You should consider upgrading via the 'python -m pip install --upgrade pip' command.<br> Exception: Traceback (most recent call last): File "C:\Python34\lib\site-packages\pip-7.1.0-py3.4.egg\pip\basecommand.py", <br>line 223, in main<br> status = self.run(options, args) File "C:\Python34\lib\site-packages\pip-7.1.0-py3.4.egg\pip\commands\install.py",<br> line 299, in run<br> root=options.root_path, File "C:\Python34\lib\site-packages\pip-7.1.0-py3.4.egg\pip\req\req_set.py",<br> line 640, in install<br> requirement.uninstall(auto_confirm=True) File "C:\Python34\lib\site-packages\pip-7.1.0-py3.4.egg\pip\req\req_install.py", <br>line 683, in uninstall<br> for path in pip.wheel.uninstallation_paths(dist):<br> File "C:\Python34\lib\site-packages\pip-7.1.0-py3.4.egg\pip\wheel.py", line 512, in unique<br> for item in fn(args, *kw): File "C:\Python34\lib\site-packages\pip-7.1.0-py3.4.egg\pip\wheel.py", line 531, in uninstallation_paths<br> r = csv.reader(FakeFile(dist.get_metadata_lines('RECORD'))) File "C:\Python34\lib\site-packages\pip-7.1.0-<br>py3.4.egg\pip_vendor\pkg_resources__init.py",<br> line 1619, in get_metadata_lines return yield_lines(self.get_metadata(name)) File "C:\Python34\lib\site-packages\pip-7.1.0-<br>py3.4.egg\pip_vendor\pkg_resources__init.py", <br>line 1616, in get_metadata return self._get(self._fn(self.egg_info, name)).decode("utf-8")<br> UnicodeDecodeError: 'utf-8' codec can't decode byte 0xcd in position 339442: <br>invalid continuation byte
value = 'old' print (value)
"""
Django settings for MyBlog project.
Generated by 'django-admin startproject' using Django 1.9.6.
For more information on this file, see
https://docs.djangoproject.com/en/1.9/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.9/ref/settings/
"""
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'z$8+858_zk!!zey@pih$7)&vv=xn-i7h45hmdeh$np2&wp*t6n'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'blog',
'loginsys',
]
MIDDLEWARE_CLASSES = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'MyBlog.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')]
,
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'django.core.context_processors.i18n',
'django.core.context_processors.media',
'django.core.context_processors.static',
'django.core.context_processors.tz',
],
},
},
]
WSGI_APPLICATION = 'MyBlog.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.9/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Password validation
# https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/1.9/topics/i18n/
LANGUAGE_CODE = 'ru-RU'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.9/howto/static-files/
STATIC_URL = '/static/'
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x02F7F540>
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\django\utils\autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "C:\Python34\lib\site-packages\django\core\management\commands\runserver.py", line 121, in inner_run
self.check(display_num_errors=True)
File "C:\Python34\lib\site-packages\django\core\management\base.py", line 385, in check
include_deployment_checks=include_deployment_checks,
File "C:\Python34\lib\site-packages\django\core\management\base.py", line 372, in _run_checks
return checks.run_checks(**kwargs)
File "C:\Python34\lib\site-packages\django\core\checks\registry.py", line 81, in run_checks
new_errors = check(app_configs=app_configs)
File "C:\Python34\lib\site-packages\django\core\checks\urls.py", line 14, in check_url_config
return check_resolver(resolver)
File "C:\Python34\lib\site-packages\django\core\checks\urls.py", line 24, in check_resolver
for pattern in resolver.url_patterns:
File "C:\Python34\lib\site-packages\django\utils\functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Python34\lib\site-packages\django\urls\resolvers.py", line 310, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "C:\Python34\lib\site-packages\django\utils\functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Python34\lib\site-packages\django\urls\resolvers.py", line 303, in urlconf_module
return import_module(self.urlconf_name)
File "C:\Python34\lib\importlib\__init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1129, in _exec
File "<frozen importlib._bootstrap>", line 1471, in exec_module
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "D:\Projects\MyBlog\MyBlog\urls.py", line 19, in <module>
from loginsys import urls
File "D:\Projects\MyBlog\loginsys\urls.py", line 2, in <module>
from loginsys import views
File "D:\Projects\MyBlog\loginsys\views.py", line 4, in <module>
from django.core.context_processors import csrf
ImportError: No module named 'django.core.context_processors'
class SOCKS_IMAP4(imaplib.IMAP4): def __init__(self, host, port = imaplib.IMAP4_PORT,proxy_type = None, proxy = None): self.proxy = proxy self.proxy_type = proxy_type imaplib.IMAP4.__init__(self, host, port) def open(self,host,port=imaplib.IMAP4_PORT): self.host = host self.port = port self.sock = socksocket() if self.proxy and self.proxy_type: proxy_ip,proxy_port = self.proxy.split(':') self.sock.setproxy(self.proxy_type,proxy_ip,int(proxy_port)) self.sock.connect((host,port)) self.file = self.sock.makefile('rb') class SOCKS_IMAP4_SSL(imaplib.IMAP4_SSL): def __init__(self, host, port = imaplib.IMAP4_SSL_PORT,proxy_type = None, proxy = None,): self.proxy = proxy self.proxy_type = proxy_type imaplib.IMAP4_SSL.__init__(self, host, port) def open(self, host, port=imaplib.IMAP4_SSL_PORT): self.host = host self.port = port self.sock = socksocket() #actual privoxy default setting, but as said, you may want to parameterize it if self.proxy and self.proxy_type: proxy_ip,proxy_port = self.proxy.split(':') self.sock.setproxy(self.proxy_type,proxy_ip,int(proxy_port)) self.sock.connect((host,port)) self.sslobj = ssl.wrap_socket(self.sock, self.keyfile, self.certfile) self.file = self.sslobj.makefile('rb')
class SOCKS_POP3(poplib.POP3): def __init__(self, host, port=poplib.POP3_PORT,timeout=socket._GLOBAL_DEFAULT_TIMEOUT,proxy_type = None, proxy = None): self.host = host self.port = port self.sock = socksocket() if proxy and proxy_type: proxy_ip,proxy_port = proxy.split(':') self.sock.setproxy(proxy_type,proxy_ip,int(proxy_port)) self.sock.connect((host, port)) self.file = self.sock.makefile('rb') self._debugging = 0 self.welcome = self._getresp() class SOCKS_POP3_SSL(poplib.POP3_SSL): def __init__(self, host, port = poplib.POP3_SSL_PORT, keyfile = None, certfile = None,proxy_type = None, proxy = None): self.host = host self.port = port self.keyfile = keyfile self.certfile = certfile self.buffer = "" #msg = "getaddrinfo returns an empty list" self.sock = socksocket() if proxy and proxy_type: proxy_ip,proxy_port = proxy.split(':') self.sock.setproxy(proxy_type,proxy_ip,int(proxy_port)) self.sock.connect((host, port)) #for res in socket.getaddrinfo(self.host, self.port, 0, socket.SOCK_STREAM): # af, socktype, proto, canonname, sa = res # try: # self.sock = socket.socket(af, socktype, proto) # self.sock.connect(sa) # except socket.error, msg: # if self.sock: # self.sock.close() # self.sock = None # continue # break #if not self.sock: # raise socket.error, msg self.file = self.sock.makefile('rb') self.sslobj = ssl.wrap_socket(self.sock, self.keyfile, self.certfile) self._debugging = 0 self.welcome = self._getresp()