Skip to content

Commit 66f319d

Browse files
author
cclauss
committed
Use print() function in both Python 2 and Python 3
1 parent e5a01db commit 66f319d

23 files changed

+114
-89
lines changed

Diff for: GroupSms_Way2.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import print_function
12
import urllib2
23
import cookielib
34
from getpass import getpass
@@ -42,4 +43,4 @@
4243
print("Error while sending message")
4344

4445
sys.exit(1)
45-
print "SMS has been sent."
46+
print("SMS has been sent.")

Diff for: Organise.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import print_function
12
import os
23
import sys
34
import shutil
@@ -40,7 +41,7 @@ def Organize(dirs, name):
4041
os.chdir(dest)
4142
shutil.move(src, '{}\\{}'.format(dest, dirs))
4243

43-
print os.getcwd()
44+
print(os.getcwd())
4445
os.chdir(destLocation)
4546

4647
TYPES_LIST = ['Video', 'Images', 'Documents', 'Music', 'Codes', 'Executables', 'Compressed']

Diff for: Shivaansh.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1+
from __future__ import print_function
12
x = input("Enter a number: ")
23
for i in range (1,11,1):
3-
print x, "x", i, "=", (x * i)
4+
print(x, "x", i, "=", (x * i))
45

Diff for: env_check.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@
2323
if newenv is None: # If it doesn't exist
2424
print(env_check, 'is not set') # Print it is not set
2525
else: # Else if it does exist
26-
print('Current Setting for {}={}\n'.format(env_check, newenv) # Print out the details)
26+
print('Current Setting for {}={}\n'.format(env_check, newenv)) # Print out the details

Diff for: get_likes_on_FB.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import print_function
12
import urllib
23
import json
34
import sys
@@ -12,7 +13,7 @@
1213
data = json.load(urllib.urlopen(url))
1314
id=0
1415

15-
print str(id)
16+
print(str(id))
1617

1718
for item in data['data']:
1819
time=item['created_time'][11:19]
@@ -32,4 +33,4 @@
3233

3334
id+=1
3435

35-
print str(id)+'\t'+ time.encode('utf-8')+'\t'+date.encode('utf-8')+'\t'+year.encode('utf-8')+'\t'+ str(num_share)+'\t'+str(num_like)
36+
print(str(id)+'\t'+ time.encode('utf-8')+'\t'+date.encode('utf-8')+'\t'+year.encode('utf-8')+'\t'+ str(num_share)+'\t'+str(num_like))

Diff for: merge.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import print_function
12
# author:zhangshuyx@gmail.com
23

34
#!/usr/bin/env python
@@ -32,8 +33,8 @@ def merge():
3233
# the main program
3334

3435
def main():
35-
print "\t\tMerge\n\n"
36-
print "This program merges csv-files to one file\n"
36+
print("\t\tMerge\n\n")
37+
print("This program merges csv-files to one file\n")
3738
merge()
3839

3940
if __name__ == '__main__':

Diff for: new_script.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import print_function
12
# Script Name : new_script.py
23
# Author : Craig Richards
34
# Created : 20th November 2012
@@ -19,11 +20,11 @@
1920
-sql : SQL Script'''
2021

2122
if len(sys.argv) < 3:
22-
print text
23+
print(text)
2324
sys.exit()
2425

2526
if '-h' in sys.argv or '--h' in sys.argv or '-help' in sys.argv or '--help' in sys.argv:
26-
print text
27+
print(text)
2728
sys.exit()
2829
else:
2930
if '-python' in sys.argv[1]:
@@ -39,7 +40,7 @@
3940
config_file = "sql.cfg"
4041
extension = ".sql"
4142
else:
42-
print 'Unknown option - ' + text
43+
print('Unknown option - ' + text)
4344
sys.exit()
4445

4546
confdir = os.getenv("my_config")

Diff for: nmap_scan.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import print_function
12
# Script Name : nmap_scan.py
23
# Author : Craig Richards
34
# Created : 24th May 2013
@@ -16,7 +17,7 @@ def nmapScan(tgtHost, tgtPort): # Create the function, this fucntion doe
1617
nmScan = nmap.PortScanner()
1718
nmScan.scan(tgtHost, tgtPort)
1819
state = nmScan[tgtHost]['tcp'][int(tgtPort)]['state']
19-
print "[*] " + tgtHost + " tcp/" + tgtPort + " " + state
20+
print("[*] " + tgtHost + " tcp/" + tgtPort + " " + state)
2021

2122

2223
def main(): # Main Program
@@ -28,7 +29,7 @@ def main(): # Main Program
2829
tgtPorts = str(options.tgtPort).split(',')
2930

3031
if (tgtHost == None) | (tgtPorts[0] == None):
31-
print parser.usage
32+
print(parser.usage)
3233
exit(0)
3334

3435
for tgtPort in tgtPorts: # Scan the hosts with the ports etc

Diff for: password_cracker.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import print_function
12
# Script Name : password_cracker.py
23
# Author : Craig Richards
34
# Created : 20 May 2013
@@ -18,7 +19,7 @@
1819
try:
1920
import fcrypt # Try importing the fcrypt module
2021
except ImportError:
21-
print 'Please install fcrypt if you are on Windows'
22+
print('Please install fcrypt if you are on Windows')
2223

2324

2425
def testPass(cryptPass): # Start the function
@@ -28,9 +29,9 @@ def testPass(cryptPass): # Start the function
2829
word = word.strip('\n')
2930
cryptWord = crypt.crypt(word, salt) # Check for password in the file
3031
if (cryptWord == cryptPass):
31-
print "[+] Found Password: "+word+"\n"
32+
print("[+] Found Password: "+word+"\n")
3233
return
33-
print "[-] Password Not Found.\n"
34+
print("[-] Password Not Found.\n")
3435
return
3536

3637

@@ -40,7 +41,7 @@ def main():
4041
if ":" in line:
4142
user = line.split(':')[0]
4243
cryptPass = line.split(':')[1].strip(' ') # Prepare the user name etc
43-
print "[*] Cracking Password For: " + user
44+
print("[*] Cracking Password For: " + user)
4445
testPass(cryptPass) # Call it to crack the users password
4546

4647
if __name__ == "__main__":

Diff for: ping_servers.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import print_function
12
# Script Name : ping_servers.py
23
# Author : Craig Richards
34
# Created : 9th May 2012
@@ -14,14 +15,14 @@
1415

1516
filename = sys.argv[0] # Sets a variable for the script name
1617
if '-h' in sys.argv or '--h' in sys.argv or '-help' in sys.argv or '--help' in sys.argv: # Help Menu if called
17-
print '''
18+
print('''
1819
You need to supply the application group for the servers you want to ping, i.e.
1920
dms
2021
swaps
2122
2223
Followed by the site i.e.
2324
155
24-
bromley'''
25+
bromley''')
2526
sys.exit(0)
2627
else:
2728

Diff for: ping_subnet.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import print_function
12
# Script Name : ping_subnet.py
23
# Author : Craig Richards
34
# Created : 12th January 2012
@@ -15,8 +16,8 @@
1516
filename = sys.argv[0] # Sets a variable for the script name
1617

1718
if '-h' in sys.argv or '--h' in sys.argv or '-help' in sys.argv or '--help' in sys.argv: # Help Menu if called
18-
print '''
19-
You need to supply the first octets of the address Usage : ''' + filename + ''' 111.111.111 '''
19+
print('''
20+
You need to supply the first octets of the address Usage : ''' + filename + ''' 111.111.111 ''')
2021
sys.exit(0)
2122
else:
2223

Diff for: portscanner.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import print_function
12
# Script Name : portscanner.py
23
# Author : Craig Richards
34
# Created : 20 May 2013
@@ -21,11 +22,11 @@ def connScan(tgtHost, tgtPort): # Start of the function
2122
connSkt.send('')
2223
results=connSkt.recv(100)
2324
screenLock.acquire() # Acquire the lock
24-
print '[+] %d/tcp open'% tgtPort
25-
print '[+] ' + str(results)
25+
print('[+] %d/tcp open'% tgtPort)
26+
print('[+] ' + str(results))
2627
except:
2728
screenLock.acquire()
28-
print '[-] %d/tcp closed '% tgtPort
29+
print('[-] %d/tcp closed '% tgtPort)
2930
finally:
3031
screenLock.release()
3132
connSkt.close()
@@ -34,13 +35,13 @@ def portScan(tgtHost, tgtPorts): # Start of the function
3435
try:
3536
tgtIP = gethostbyname(tgtHost) # Get the IP from the hostname
3637
except:
37-
print "[-] Cannot resolve '%s': Unknown host"%tgtHost
38+
print("[-] Cannot resolve '%s': Unknown host"%tgtHost)
3839
return
3940
try:
4041
tgtName = gethostbyaddr(tgtIP) # Get hostname from IP
41-
print '\n[+] Scan Results for: ' +tgtName[0]
42+
print('\n[+] Scan Results for: ' +tgtName[0])
4243
except:
43-
print '\n[+] Scan Results for: ' + tgtIP
44+
print('\n[+] Scan Results for: ' + tgtIP)
4445
setdefaulttimeout(1)
4546
for tgtPort in tgtPorts: # Scan host and ports
4647
t = Thread(target=connScan, args=(tgtHost, int(tgtPort)))
@@ -54,7 +55,7 @@ def main():
5455
tgtHost = options.tgtHost
5556
tgtPorts = str(options.tgtPort).split(',')
5657
if (tgtHost == None) | (tgtPorts[0] == None):
57-
print parser.usage
58+
print(parser.usage)
5859
exit(0)
5960
portScan(tgtHost, tgtPorts)
6061
if __name__ == '__main__':

Diff for: powerup_checks.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import print_function
12
# Script Name : powerup_checks.py
23
# Author : Craig Richards
34
# Created : 25th June 2013
@@ -63,27 +64,27 @@ def get_servers(query): # Function to get the ser
6364
break
6465
f = open(serverfile, 'a') # Open the serverfile
6566
f.write("%s\n" % str(row[0])) # Write the server out to the file
66-
print row[0] # Display the server to the screen
67+
print(row[0]) # Display the server to the screen
6768
f.close() # Close the file
6869

6970
def main(): # Main Function
7071
if os.path.exists(serverfile): # Checks to see if there is an existing server file
7172
os.remove(serverfile) # If so remove it
7273

7374
if len(sys.argv) < 2: # Check there is an argument being passed
74-
print text # Display the help text if there isn't one passed
75+
print(text) # Display the help text if there isn't one passed
7576
sys.exit() # Exit the script
7677

7778
if '-h' in sys.argv or '--h' in sys.argv or '-help' in sys.argv or '--help' in sys.argv: # If the ask for help
78-
print text # Display the help text if there isn't one passed
79+
print(text) # Display the help text if there isn't one passed
7980
sys.exit(0) # Exit the script after displaying help
8081
else:
8182
if sys.argv[1].lower().startswith('-site1'): # If the argument is site1
8283
query = 'site1' # Set the variable to have the value site
8384
elif sys.argv[1].lower().startswith('-site2'): # Else if the variable is bromley
8485
query = 'site2' # Set the variable to have the value bromley
8586
else:
86-
print '\n[-] Unknown option [-] ' + text # If an unknown option is passed, let the user know
87+
print('\n[-] Unknown option [-] ' + text) # If an unknown option is passed, let the user know
8788
sys.exit(0)
8889
get_servers(query) # Call the get servers funtion, with the value from the argument
8990

Diff for: pscheck.py

+14-10
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,36 @@
88

99
# Description : Process check on Nix boxes, diplsay formatted output from ps command
1010

11-
import commands, os, string
11+
import commands
12+
import os
13+
import string
14+
1215

1316
def ps():
1417
program = raw_input("Enter the name of the program to check: ")
1518

1619
try:
17-
#perform a ps command and assign results to a list
20+
# perform a ps command and assign results to a list
1821
output = commands.getoutput("ps -f|grep " + program)
1922
proginfo = string.split(output)
2023

21-
#display results
22-
print "\n\
24+
# display results
25+
print("\n\
2326
Full path:\t\t", proginfo[5], "\n\
2427
Owner:\t\t\t", proginfo[0], "\n\
2528
Process ID:\t\t", proginfo[1], "\n\
2629
Parent process ID:\t", proginfo[2], "\n\
27-
Time started:\t\t", proginfo[4]
30+
Time started:\t\t", proginfo[4])
2831
except:
29-
print "There was a problem with the program."
32+
print("There was a problem with the program.")
33+
3034

3135
def main():
3236
if os.name == "posix": # Unix/Linux/MacOS/BSD/etc
3337
ps() # Call the function
3438
elif os.name in ("nt", "dos", "ce"): # if the OS is windows
35-
print "You need to be on Linux or Unix to run this"
36-
37-
39+
print("You need to be on Linux or Unix to run this")
40+
41+
3842
if __name__ == '__main__':
39-
main()
43+
main()

Diff for: psunotify.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import print_function
12
import mechanize
23
import re
34
import urllib2
@@ -19,7 +20,7 @@
1920
urls[int]=urls[int].replace("<b>","")
2021
urls[int]=urls[int].replace("</b>","")
2122
int=int+1
22-
print urls
23+
print(urls)
2324
for url in urls:
2425
try:
2526
temp=url.split("/")
@@ -31,7 +32,7 @@
3132
file=open('psu2'+q+'.pdf','wb')
3233
file.write(r.read())
3334
file.close()
34-
print "Done"
35+
print("Done")
3536
except urllib2.URLError as e:
36-
print "Sorry there exists a problem with this URL Please Download this Manually "+str(url)
37+
print("Sorry there exists a problem with this URL Please Download this Manually "+str(url))
3738

Diff for: python_sms.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import print_function
12
# Script Name : python_sms.py
23
# Author : Craig Richards
34
# Created : 16th February 2017
@@ -63,14 +64,14 @@
6364
postdata = urllib.urlencode(values)
6465
req = urllib2.Request(url, postdata)
6566

66-
print ('Attempting to send SMS to '+ sname + ' at ' + snumber + ' on ' + tdate)
67-
f.write ('Attempting to send SMS to '+ sname + ' at ' + snumber + ' on ' + tdate + '\n')
67+
print('Attempting to send SMS to '+ sname + ' at ' + snumber + ' on ' + tdate)
68+
f.write('Attempting to send SMS to '+ sname + ' at ' + snumber + ' on ' + tdate + '\n')
6869

6970
try:
7071
response = urllib2.urlopen(req)
7172
response_url = response.geturl()
7273
if response_url == url:
73-
print 'SMS sent!'
74-
except urllib2.URLError, e:
75-
print 'Send failed!'
76-
print e.reason
74+
print('SMS sent!')
75+
except urllib2.URLError as e:
76+
print('Send failed!')
77+
print(e.reason)

Diff for: recyclebin.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import print_function
12
# Script Name : recyclebin.py
23
# Author : Craig Richards
34
# Created : 07th June 2013
@@ -35,9 +36,9 @@ def findRecycled(recycleDir): # Start of the function, list the contents of the
3536
for sid in dirList:
3637
files = os.listdir(recycleDir + sid)
3738
user = sid2user(sid)
38-
print '\n[*] Listing Files for User: ' + str(user)
39+
print('\n[*] Listing Files for User: ' + str(user))
3940
for file in files:
40-
print '[+] Found File: ' + str(file)
41+
print('[+] Found File: ' + str(file))
4142

4243
def main():
4344
recycleDir = returnDir()

0 commit comments

Comments
 (0)