Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
J
jumpserver
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ops
jumpserver
Commits
63065f5c
Commit
63065f5c
authored
Oct 31, 2014
by
guanghongwei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
使用pxssh
parent
de283722
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
33 deletions
+18
-33
jumpserver.iml
.idea/jumpserver.iml
+1
-1
jumpserver.py
jumpserver.py
+15
-32
pip-requirement.txt
pip-requirement.txt
+2
-0
No files found.
.idea/jumpserver.iml
View file @
63065f5c
...
...
@@ -2,7 +2,7 @@
<module
type=
"PYTHON_MODULE"
version=
"4"
>
<component
name=
"NewModuleRootManager"
>
<content
url=
"file://$MODULE_DIR$"
/>
<orderEntry
type=
"jdk"
jdkName=
"Python 2.7.
8 (C:\Python27\
python.exe)"
jdkType=
"Python SDK"
/>
<orderEntry
type=
"jdk"
jdkName=
"Python 2.7.
6 (C:/Python27/
python.exe)"
jdkType=
"Python SDK"
/>
<orderEntry
type=
"sourceFolder"
forTests=
"false"
/>
</component>
</module>
...
...
jumpserver.py
View file @
63065f5c
...
...
@@ -16,6 +16,7 @@ from Crypto.Cipher import AES
from
binascii
import
b2a_hex
,
a2b_hex
import
ConfigParser
import
paramiko
import
pxssh
base_dir
=
"/opt/jumpserver/"
cf
=
ConfigParser
.
ConfigParser
()
...
...
@@ -110,38 +111,20 @@ def connect(host, port, user, password):
os
.
mkdir
(
log_date_dir
)
logfile
=
open
(
"
%
s/
%
s_
%
s"
%
(
log_date_dir
,
host
,
user
),
'a'
)
logfile
.
write
(
'
\n\n
%
s
\n\n
'
%
time
.
strftime
(
'
%
Y
%
m
%
d_
%
H
%
M
%
S'
))
cmd
=
'ssh -q -p
%
s
%
s@
%
s'
%
(
port
,
user
,
host
)
global
foo
foo
=
pexpect
.
spawn
(
'/bin/bash'
,
[
'-c'
,
cmd
])
foo
.
logfile
=
logfile
while
True
:
index
=
foo
.
expect
([
'continue'
,
'assword'
,
pexpect
.
EOF
,
pexpect
.
TIMEOUT
],
timeout
=
3
)
if
index
==
0
:
foo
.
sendline
(
'yes'
)
continue
elif
index
==
1
:
foo
.
sendline
(
password
)
index
=
foo
.
expect
([
'assword'
,
'.*'
,
pexpect
.
EOF
,
pexpect
.
TIMEOUT
],
timeout
=
3
)
if
index
==
1
:
signal
.
signal
(
signal
.
SIGWINCH
,
sigwinch_passthrough
)
size
=
getwinsize
()
foo
.
setwinsize
(
size
[
0
],
size
[
1
])
foo
.
interact
()
break
elif
index
==
0
:
print
"Password error."
break
else
:
print
"Login failed, please contact system administrator!"
break
foo
.
terminate
(
force
=
True
)
try
:
global
foo
foo
=
pxssh
.
pxssh
()
foo
.
login
(
host
,
user
,
password
,
port
=
port
,
auto_prompt_reset
=
False
)
foo
.
logfile
=
logfile
foo
.
sendline
(
''
)
signal
.
signal
(
signal
.
SIGWINCH
,
sigwinch_passthrough
)
size
=
getwinsize
()
foo
.
setwinsize
(
size
[
0
],
size
[
1
])
foo
.
interact
()
except
pxssh
.
ExceptionPxssh
as
e
:
print
(
'密码错误:
%
s'
%
e
)
except
KeyboardInterrupt
:
foo
.
logout
()
def
ip_all_select
(
username
):
...
...
pip-requirement.txt
0 → 100644
View file @
63065f5c
pexpect == 3.3
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment