Chinaunix首页 | 论坛 | 博客
  • 博客访问: 424764
  • 博文数量: 72
  • 博客积分: 1599
  • 博客等级: 上尉
  • 技术积分: 1125
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-16 13:22
文章分类

全部博文(72)

文章存档

2014年(3)

2013年(8)

2012年(23)

2011年(23)

2010年(15)

分类:

2012-04-24 20:23:45

问题现象:生成IOU License的时候出现struct.error

  1. [root@192_168_160_202 IOU]# ./crack.py
  2.     *********************************************************************
  3.     Cisco IOU License Generator - Kal 2011, python port of 2006 C version
  4.     hostid=a8c0caa0, hostname=192_168_160_202, ioukey=a8c0ce23L
  5.     Traceback (most recent call last):
  6.       File "./crack.py", line 18, in <module>
  7.         md5input=iouPad1 + iouPad2 + struct.pack('!i', ioukey) + iouPad1
  8.     struct.error: integer out of range for 'i' format code

分析:可能是由于不同机器算出来的值不一样,转换整数的时候溢出。超出'i'的范围那就换类型,用I,l或L可能就行了(具体见后面说明)。

原先第18行是这样的:
  1. md5input=iouPad1 + iouPad2 + struct.pack('!i', ioukey) + iouPad1
现在将i改成L
  1. md5input=iouPad1 + iouPad2 + struct.pack('!L', ioukey) + iouPad1
测试成功:

  1. [root@192_168_160_202 IOU]# ./crack.py
  2.     *********************************************************************
  3.     Cisco IOU License Generator - Kal 2011, python port of 2006 C version
  4.     hostid=a8c0caa0, hostname=192_168_160_202, ioukey=a8c0ce23L
  5.     Add the following text to ~/.iourc:
  6.     [license]
  7.     192_168_160_202 = 0c3838fa36b12ed4;
  8.     You can disable the phone home feature with something like:
  9.      echo '127.0.0.127 xml.cisco.com' >> /etc/hosts

说明:
函数的用法是这样的:struct.pack(format, data)
    The optional first format char indicates byte order, size and alignment:
     @: native order, size & alignment (default)
     =: native order, std. size & alignment
     <: little-endian, std. size & alignment
     >: big-endian, std. size & alignment
     !: same as >
   
    The remaining chars indicate types of args and must match exactly;
    these can be preceded by a decimal repeat count:
     x: pad byte (no data); c:char; b:signed byte; B:unsigned byte;
     h:short; H:unsigned short; i:int; I:unsigned int;
     l:long; L:unsigned long; f:float; d:double.
    Special cases (preceding decimal count indicates length):
     s:string (array of char); p: pascal string (with count byte).
    Special case (only available in native format):
     P:an integer type that is wide enough to hold a pointer.
    Special case (not in native mode unless 'long long' in platform C):
     q:long long; Q:unsigned long long
    Whitespace between formats is ignored.

有时将hostname改短一点也能成功,但不推荐。

阅读(5837) | 评论(0) | 转发(0) |
0

上一篇:从源头排错

下一篇:IBM刀片硬盘脱阵列

给主人留下些什么吧!~~