Created
December 2, 2015 09:02
-
-
Save addminuse/7747903cd420b15f17e0 to your computer and use it in GitHub Desktop.
Enable port forwarding using this simple python script.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/usr/bin/python | |
# if yes or no doesn't work try using quotes | |
# example 'yes' or 'no' | |
import os | |
import sys | |
print('\n'*2) | |
print('If yes and no throws an error try using quotes.') | |
print('Example "Yes" or "no" or "Yeah"') | |
print('\n'*2) | |
while True: | |
try: | |
fo = open('/proc/sys/net/ipv4/ip_forward','r') | |
print('*******************************************************************') | |
print('Current value inside the file is: ') | |
print(fo.read()) | |
print('Enable or Disable port Forwarding.') | |
x1 = input('To continue type Y and to end press N.''\n') | |
y = str(x1) | |
x = y.lower() | |
if x[0] == 'y' and (x == 'yes' or x == 'yup' or x == 'yeah' or x == 'ya' or x =='yo' or x == 'y') and len(x)<=4: | |
fo1 = open('/proc/sys/net/ipv4/ip_forward','w') | |
print('\n'*1) | |
print('Please enter either 0 or 1\n\n0 = port forwarding disabled\n1 = port forwarding enabled') | |
print('\n'*1) | |
n = int(input('Please enter the value''\n')) | |
if n == 0: | |
fo1.write('0') | |
fo1.close() | |
print('\n'*1) | |
print('Port forwarding is disabled.') | |
print('*******************************************************************') | |
break | |
elif n == 1: | |
fo1.write('1') | |
fo1.close() | |
print('\n'*1) | |
print('Port forwarding is enabled.') | |
print('*******************************************************************') | |
break | |
else: | |
print('\n'*1) | |
print('Wrong value, Try again') | |
print('Only 0 and 1 is accepted') | |
print('\n'*1) | |
print('Resetting Program') | |
elif x[0] == 'n' and len(x)<=5 and (x == 'no' or x == 'nope' or x == 'nahh' or x == 'nopes' or x == 'n'): | |
print('\n'*1) | |
print('Quitting.........') | |
print('*******************************************************************') | |
break | |
else: | |
print('\n'*1) | |
print('Please either type yes or no') | |
print('Resetting Program') | |
except Exception as e: #Exception Block | |
print('You encountered an error: ',str(e)) | |
print('Resetting Program') | |
print('Please Try again') | |
print('\n'*1) | |
print('*******************************************************************') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment