python-模块间的导入与os.system('xxx')的shell命令执行

在一个大模块中导入一个小的特定子模块,如在sys大模块中导入sys.path的子模块,其他的sys子模块无法使用

root@kali:~# python
Python 2.7.3 (default, Mar 14 2014, 11:57:14)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from sys import path       //导入子模块sys.path
>>> sys.version_info
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'sys' is not defined
>>> path
['', '/usr/local/lib/python2.7/dist-packages/frida-4.4.0-py2.7-linux-i686.egg', '/usr/local/lib/python2.7/dist-packages/Pygments-2.0.2-py2.7.egg', '/usr/local/lib/python2.7/dist-packages/prompt_toolkit-0.45-py2.7.egg', '/usr/local/lib/python2.7/dist-packages/colorama-0.3.3-py2.7.egg', '/usr/local/lib/python2.7/dist-packages/wcwidth-0.1.4-py2.7.egg', '/usr/local/lib/python2.7/dist-packages/six-1.9.0-py2.7.egg', '/usr/local/lib/python2.7/dist-packages/androguard-3.0-py2.7.egg', '/usr/lib/python2.7/dist-packages/pybloomfiltermmap-0.3.11-py2.7-linux-i686.egg', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-linux2', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PIL', '/usr/lib/python2.7/dist-packages/gtk-2.0', '/usr/lib/pymodules/python2.7', '/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode']
>>>


导入两个子模块的方式

root@kali:~# python
Python 2.7.3 (default, Mar 14 2014, 11:57:14)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from sys import path,version_info        //导入两个子模块的方式
>>> path
['', '/usr/local/lib/python2.7/dist-packages/frida-4.4.0-py2.7-linux-i686.egg', '/usr/local/lib/python2.7/dist-packages/Pygments-2.0.2-py2.7.egg', '/usr/local/lib/python2.7/dist-packages/prompt_toolkit-0.45-py2.7.egg', '/usr/local/lib/python2.7/dist-packages/colorama-0.3.3-py2.7.egg', '/usr/local/lib/python2.7/dist-packages/wcwidth-0.1.4-py2.7.egg', '/usr/local/lib/python2.7/dist-packages/six-1.9.0-py2.7.egg', '/usr/local/lib/python2.7/dist-packages/androguard-3.0-py2.7.egg', '/usr/lib/python2.7/dist-packages/pybloomfiltermmap-0.3.11-py2.7-linux-i686.egg', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-linux2', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PIL', '/usr/lib/python2.7/dist-packages/gtk-2.0', '/usr/lib/pymodules/python2.7', '/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode']
>>>
>>> version_info
sys.version_info(major=2, minor=7, micro=3, releaselevel='final', serial=0)
>>>


导入大模块
>>>
>>> import sys,os    //导入两个大模块的方式
>>> os.system('pwd')
/root
0
>>> os.system('uname-a')
sh: 1: uname-a: not found
32512
>>>
>>> from sys import version_info as v     //使用别名,除非名字非常长才用
>>> v
sys.version_info(major=2, minor=7, micro=3, releaselevel='final', serial=0)
>>>


os.system('xxxx')就是shell命令执行语句

>>> os.system('pwd')
/root
0
>>> os.system('df -a')
文件系统                                                  1K-块    已用    可用 已用% 挂载点
rootfs                                                 19620732 8692020 9908964   47% /
sysfs                                                         0       0       0     - /sys
proc                                                          0       0       0     - /proc
udev                                                      10240       0   10240    0% /dev
devpts                                                        0       0       0     - /dev/pts
tmpfs                                                     51188     568   50620    2% /run
/dev/disk/by-uuid/1d69c4b7-8825-4a6e-a4a4-e1ef94f2d30f 19620732 8692020 9908964   47% /
tmpfs                                                      5120       0    5120    0% /run/lock
tmpfs                                                    282580     564  282016    1% /run/shm
fusectl                                                       0       0       0     - /sys/fs/fuse/connections
vmware-vmblock                                                0       0       0     - /run/vmblock-fuse
binfmt_misc                                                   0       0       0     - /proc/sys/fs/binfmt_misc
0
>>>




阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/xwbk12/article/details/72353930
个人分类: pyhton
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

python-模块间的导入与os.system('xxx')的shell命令执行

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭