4

I need some advice with a Python script. I'm still new and learned it by myself. I found the script on Google. After I retype it, it doesn't print the result in the console. How can the result of the script be shown in the console? Details as below:

C:\Python27>test1.py af8978b1797b72acfff9595a5a2a373ec3d9106d

C:\Python27>

After I press enter, nothing happens. Should the result be shown or not?

Here's the code that I retyped:

#!/usr/bin/python
#coding: ascii

import requests
import sys
import re

url = 'http://hashtoolkit.com/reverse-hash?hash='
try:
    hash = sys.argv[1]
except:
     print ("usage: python "+sys.argv[0]+" hash")
sys.exit()

http = request.get(url+hash)
content = http.content
cracked = re.findall("<span title=\*decrypted (md5|sha1|sha384|sha512) hash\*>(.*)</span>", content) # expression regular
print ("\n\tAlgoritmo: "+cracked[0][0])
print ("\tPassword Cracked: "+cracked[0][1])
Eryk Sun
  • 33,190
  • 5
  • 92
  • 111
Ajinata
  • 41
  • 1
  • 1
  • 3

2 Answers2

6

The first line in your script is called a Shebang line. A Shebang line tells the script to run the Python interpreter from that location.

The shebang line you provided is a Linux system path, but it looks from the path you are executing Python from, that you are running on Windows.

You can do one of two things here to fix that:

  • Remove the Shebange Line.
  1. Remove the first line from your script.
  2. Execute the script using python test1.py COMMAND_LINE_ARGUMENTS
  • Modify Your Shebang line.
  1. Change the first line of your script from !/usr/bin/python to #!python (This is assuming that python is in your systems PATH variable.)`

  2. Execute the script using test1.py COMMAND_LINE_ARGUMENTS

Also, you are trying to import the requests module that is not installed in the standard library.

If you haven't installed this yet, you can do so by going to your Python install directory and go to the scripts folder.

Hold shift and right click and go Open command window here

Type pip install requests and hit enter.

After that you should be good to go, execute the script by navigating to it and type test.py COMMAND_LINE_ARGUMENT

If a Python script doesn't have the shebang line:

python test.py COMMAND_LINE_ARGUMENT

Jebby
  • 1,845
  • 1
  • 12
  • 25
  • nice answer! but i recommend you to rewrite your answer as beauty format... – DRPK Nov 10 '17 at 17:04
  • If shebangs are supported in Windows, it's due to associating .py files with Python 3's py.exe launcher. The launcher supports common Unix paths in shebangs such as `!/usr/bin/python`, which will prefer the highest version of Python 2 that's installed over Python 3 since `python` in Unix systems is typically Python 2. A shebang line is not required. The launcher will use its default version if no shebang is found; also, some (typically 2.x) installations associate .py with python.exe directly. Please read the [docs](https://docs.python.org/3/using/windows.html#python-launcher-for-windows). – Eryk Sun Nov 10 '17 at 23:58
  • already done as adviced but still same thing happen.not showing the result on cmd promt screen – Ajinata Nov 11 '17 at 01:17
  • after type the script test1.py command_line_argument and execute,return back to nothing – Ajinata Nov 11 '17 at 01:52
  • @Ajinata After a little further inspection of your code, I saw that `sys.exit()` wasn't inside your `except` block. Indent `sys.exit()` over so it matches the indentation above it. Also, `http = request.get(url+hash)` should be `http = requests.get(url+hash)` – Jebby Nov 11 '17 at 10:41
  • @Jebby tks buddy.will try to correct it n update a.s.a.p. – Ajinata Nov 16 '17 at 04:15
0

you need to run your script using python. try:

C:\Python27>python test1.py af8978b1797b72acfff9595a5a2a373ec3d9106d
punkrockpolly
  • 9,270
  • 6
  • 36
  • 37
  • He has a shebang line at the top of his script. That tells the script to use Python automatically. He's just using a Linux shebang instead of a Windows one. – Jebby Nov 10 '17 at 16:49
  • ah...noted.will try to modified the scrip.tks dude – Ajinata Nov 11 '17 at 01:04