color.py


SUBMITTED BY: Guest

DATE: Dec. 3, 2013, 10:42 a.m.

FORMAT: Python

SIZE: 3.4 kB

HITS: 905

  1. __doc__='''
  2. Mst=>libs=>color
  3. This lib is originally bundled with MST for android, a pen testing platform specifically for android.
  4. If you wish to get the original MST for android, google for "mst_for_android.rar", there are some files
  5. from baidu cloud storage. The original file size is just about 60.9 KB, or else, you can contact me at
  6. z3r0.mhu@gmail.com to get it.
  7. Thanks for the original Author Mr.X for developing such useful library.
  8. This message is left here by Anubis from MSF Forum. [http://www.4sectors.com/forum]
  9. You can contact me at z3r0.mhu[at]gmail[dot]com
  10. Example Usage :
  11. ===============
  12. >> from color import *
  13. >> color.cprint("HELLO",RED)
  14. >> HELLO
  15. >> color.cprint("WORLD",BLACK)
  16. >> WORLD
  17. Module directory:
  18. =================
  19. - color.py
  20. |__ color (Color Object Instance)
  21. |____ cprint (Method)
  22. | Usage : cprint("TEXT HERE",COLOR)
  23. | COLORS = BLACK, BLUE, GREEN, CYAN,
  24. | RED PURPLE, YELLOW, WHITE, GREY
  25. |
  26. |____ set_cmd_text_color (Method)
  27. | Usage : set_cmd_text_color(COLOR)
  28. |____
  29. '''
  30. from os import name
  31. if name == 'nt':
  32. '''windows color table'''
  33. #global BLACK,BLUE,GREEN,CYAN,RED,PURPLE,YELLOW,WHITE,GREY
  34. BLACK = 0x0
  35. BLUE = 0x01
  36. GREEN = 0x02
  37. CYAN = 0x03
  38. RED = 0x04
  39. PURPLE= 0x05
  40. YELLOW= 0x06
  41. WHITE = 0x07
  42. GREY = 0x08
  43. else:
  44. '''other os color table'''
  45. #global BLACK,BLUE,GREEN,CYAN,RED,PURPLE,YELLOW,WHITE,GREY
  46. BLACK = '\033[0m'
  47. BLUE = '\033[34m'
  48. GREEN = '\033[32m'
  49. CYAN = '\033[36m'
  50. RED = '\033[31m'
  51. PURPLE= '\033[35m'
  52. YELLOW= '\033[33m'
  53. WHITE = '\033[37m'
  54. GREY = '\033[38m'
  55. wincode = """
  56. class ntcolor:
  57. '''windows cmd color'''
  58. try:
  59. STD_INPUT_HANDLE = -10
  60. STD_OUTPUT_HANDLE= -11
  61. STD_ERROR_HANDLE = -12
  62. import ctypes
  63. std_out_handle = ctypes.windll.kernel32.GetStdHandle(STD_OUTPUT_HANDLE)
  64. def set_cmd_text_color(self,color, handle=std_out_handle):
  65. '''set color'''
  66. bool = self.ctypes.windll.kernel32.SetConsoleTextAttribute(handle, color)
  67. return bool
  68. def resetColor(self):
  69. '''reset color'''
  70. self.set_cmd_text_color(RED|GREEN|BLUE)
  71. def cprint(self,msg,color=BLACK,enter=1):
  72. '''print color message'''
  73. self.set_cmd_text_color(color|color|color)
  74. if enter == 1:
  75. print msg
  76. else:
  77. print msg,
  78. self.resetColor()
  79. except:
  80. pass
  81. """
  82. otcode = """
  83. class otcolor:
  84. '''other os terminal color'''
  85. def cprint(self,msg,color=BLACK,enter=1):
  86. '''print color message'''
  87. if enter == 1:
  88. print color+msg+BLACK
  89. else:
  90. print color+msg+BLACK,
  91. """
  92. if __name__ == '__main__':
  93. print __doc__
  94. else:
  95. if name == 'nt':
  96. exec(wincode)
  97. color = ntcolor()
  98. else:
  99. exec(otcode)
  100. color = otcolor()

comments powered by Disqus