免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 5906 | 回复: 4
打印 上一主题 下一主题

python pexpect模块 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2013-08-15 16:16 |只看该作者 |倒序浏览
本帖最后由 helloiac 于 2013-08-15 16:17 编辑

  1. [cbb@ iac tmp]$ python test.py
  2. Generating RSA private key, 1024 bit long modulus
  3. ..++++++
  4. ....++++++
  5. e is 65537 (0x10001)
  6. [cbb@ iac tmp]$ ls
  7. ca.crt  create_crt.py   CRX_75DAF8CB7768  hsperfdata_cbb  ssh-mWY5rjnn01nK        test.py
  8. ca.key  create_crt.pyc  fcitx-socket-:0   server.key      systemd-private-5p7flS


  9. [cbb@ iac tmp]$ cat test.py
  10. #!/usr/bin/env python
  11. import pexpect
  12. import os
  13. path = './'
  14. name = 'server'
  15. domain = 'www.test.com'
  16. os.system('openssl genrsa -out %s%s.key 1024' % (path, name))
  17. child = pexpect.spawn("openssl req -new -key %s%s.key -out %s%s.csr" % (path, name, path, name))
  18. child.expect("Country Name")
  19. child.sendline("CN")
  20. child.expect("Province Name")
  21. child.sendline("abc")
  22. child.expect("Locality Name")
  23. child.sendline("abc")
  24. child.expect("Organization Name")
  25. child.sendline("aa")
  26. child.expect("Organizational Unit Name")
  27. child.sendline("aa")
  28. child.expect("Common Name")
  29. child.sendline("%s" % domain)
  30. child.expect("Email Address")
  31. child.sendline("")
  32. child.expect("password")
  33. child.sendline("")
  34. child.expect("An optional company name")
  35. child.sendline("")
复制代码
初学python
程序没有报错,可以生成server.key,但是无法生成server.csr
求解

论坛徽章:
16
IT运维版块每日发帖之星
日期:2015-10-02 06:20:00IT运维版块每月发帖之星
日期:2015-09-11 19:30:52IT运维版块每周发帖之星
日期:2015-09-11 19:20:31IT运维版块每日发帖之星
日期:2015-08-26 06:20:00每日论坛发贴之星
日期:2015-08-20 06:20:00IT运维版块每日发帖之星
日期:2015-08-20 06:20:002015年辞旧岁徽章
日期:2015-03-03 16:54:15金牛座
日期:2014-05-04 16:58:09双子座
日期:2013-12-17 16:44:37辰龙
日期:2013-11-22 15:20:59狮子座
日期:2013-11-18 22:55:08射手座
日期:2013-11-12 10:54:26
2 [报告]
发表于 2013-08-16 08:30 |只看该作者
http://blog.csdn.net/pbymw8iwm/article/details/6718962

看下那个pexpect的child地方多2个参数。。。

论坛徽章:
4
双子座
日期:2014-08-28 10:08:002015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:58:112015年亚洲杯之阿联酋
日期:2015-03-13 03:25:15
3 [报告]
发表于 2013-08-16 09:14 |只看该作者
不如手动执行一次,看看错在哪里咯

论坛徽章:
0
4 [报告]
发表于 2013-08-16 10:01 |只看该作者
找到问题了,是定义path的时候使用了'./'所以不行
是'/'出现的问题
定义为path = '.' 也没有问题
这个是为什么呢

论坛徽章:
0
5 [报告]
发表于 2013-08-16 11:21 |只看该作者
  1. [cbb@ iac tmp]$ python test.py
  2. Please input a password of ca.key: abcdefg
  3. Please input the Common name for ca.crt: uuuu
  4. [cbb@ iac tmp]$ ls
  5. ca.key  create_crt.py  CRX_75DAF8CB7768  fcitx-socket-:0  ssh-ONSNRvqG4uEM  systemd-private-cYIrep  test.py
  6. [cbb@ iac tmp]$ cat test.py
  7. #!/usr/bin/env pyhton
  8. # -*- condig:UTF-8 -*-
  9. import pexpect
  10. import os
  11. def create_ca():
  12.         ca_passwd = raw_input('Please input a password of ca.key: ')
  13.         domain = raw_input('Please input the Common name for ca.crt: ')
  14.         child = pexpect.spawn('/usr/bin/openssl req -new -x509 -keyout ca.key -out ca.crt')
  15.         child.expect('phrase')
  16.         child.sendline('%s' % ca_passwd)
  17.         child.expect('Verifying')
  18.         child.sendline('%s' % ca_passwd)
  19.         child.expect('Country Name')
  20.         child.sendline('CN')
  21.         child.expect('Province Name')
  22.         child.sendline('Fujian')
  23.         child.expect('Locality Name')
  24.         child.sendline('XiaMen')
  25.         child.expect('Organization Name')
  26.         child.sendline('hy')
  27.         child.expect('Unit Name')
  28.         child.sendline('hy')
  29.         child.expect('Common Name')
  30.         child.sendline('%s' % domain)
  31.         child.expect('Email Address')
  32.         child.sendline('')

  33. create_ca()
  34. ------------------------------------
  35. [cbb@ iac tmp]$ /usr/bin/openssl req -new -x509 -keyout ca.key -out ca.crt
  36. Generating a 2048 bit RSA private key
  37. .....................................................................+++
  38. .....................+++
  39. writing new private key to 'ca.key'
  40. Enter PEM pass phrase:
  41. Verifying - Enter PEM pass phrase:
  42. -----
  43. You are about to be asked to enter information that will be incorporated
  44. into your certificate request.
  45. What you are about to enter is what is called a Distinguished Name or a DN.
  46. There are quite a few fields but you can leave some blank
  47. For some fields there will be a default value,
  48. If you enter '.', the field will be left blank.
  49. -----
  50. Country Name (2 letter code) [XX]:CN
  51. State or Province Name (full name) []:Fujian
  52. Locality Name (eg, city) [Default City]:XiaMen
  53. Organization Name (eg, company) [Default Company Ltd]:hy
  54. Organizational Unit Name (eg, section) []:hy
  55. Common Name (eg, your name or your server's hostname) []:uuuu
  56. Email Address []:
  57. [cbb@ iac tmp]$ ls
  58. ca.crt  ca.key  create_crt.py  CRX_75DAF8CB7768  fcitx-socket-:0  ssh-ONSNRvqG4uEM  systemd-private-cYIrep  test.py
复制代码
用脚本无法生成ca.crt,只会生成ca.key
在shell用指令敲下就没有这个问题
为什么呐呐呐呐阿
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP