String Format

python

#1


Ok so i am learning python ive been getting on quite well until i stumbled upon a small problem i would like the user to input a value input and store it to a variable then i would like a string printed from the .format method ive added my code below please dont laugh lol hoping a python expert can help me thanks in advance.

SyntaxError: unexpected EOF while parsing


interface = str(input("Enter wireless interface name: "))
print (interface)
print ("reaver {0:1}{1:1}".format("-i",str(interface))


String Formatting works in CodeCademy, But not Python itself
String Formatting works in CodeCademy, But not Python itself
#2

http://www.python-course.eu/python3_input.php

The input of the user will be returned as a string without any changes.

That means we don't have to cast the input to a string, only other data types as needed by the program. Same applies with, str(interface).

So now we have,

interface = input("Enter wireless interface name: ")
print (interface)
print ("reaver {0} {1}".format("-i",interface)

and can start looking for the exception, which must surely be in the last line.

Oddly enough, it's a simple error, a missing paren to close the print statement.

>>> 
===================== RESTART: D:/Python35/interface.py =====================
Enter wireless interface name: mydlink
mydlink
reaver -i mydlink
>>>

#3

Thanks this helps explain my problem down to a tea.

if you dont mind could you check out where ive went wrong here

print ("ESSID OF AP")
essidinput = str(input("What is the ESSID of the access point you are targeting ?: "))
if address == (essidinput):
os.system("sudo macchanger %s-m " + str(interface) + str(macchange))
elif address == no:
os.system("sudo macchanger %s-r " + str(interface))
else:
print ("Script will now contuine without changing mac address.")
time.sleep(2)
timeout = str(input("How much timeout do you want to give reaver ?: "))
time.sleep(2)
timecap = int(input("How much time in seconds for distance between pin atempts type [s]skip for defualt: "))
if timecap == 100 > 1:
os.system("sudo reaver {0}{1}".format("-i",interface)
elif timecap == 1 < 100:
os.system("sudo reaver {0}{1}".format("-i",interface)
else: print ("You entered an incorrect value")

im unsure how to add if elif and else for the operation i understand that
x = hello
if group == x

basically the user must type s for skip or enter a number to delay time.

sorry if this sounds silly ive watched alot of videos trying to find the answer but the videos are to basic x > y.

this is my error:

File "/home/manjaro/Desktop/Programing/My Scripts/testscript.py", line 56
elif timecap == 1 < 100:
^
SyntaxError: invalid syntax

ive also tryed with timeout = skip etc nothing works

cheers

Craig


#4

There is still some string type casting in your input statements, and else where that is not necessary.

timecap = int(input(

When the uses presses s it will raise an exception. s cannot be converted to int.

if timecap -- 100 > 1:

is the same as asking if timecap is True ( 100 > 1 => True), You may wish to reconsider the conditions in both this and the elif.


#5

could i add like this
if timecap = int(input) = true
elif == s = true sorry for the hasstle im really new at this.


#6

No.

from numbers import Number  # at top of code

timecap = input('...')
if isinstance(timecap, Number):
    # code for when input is a number
    # now it is safe to write `int(timecap)`
else:
    # skip

Here we don't check the value of the string, but could have in the else clause. It would be moot, though, unless needed further in the code.

Even though the input is a string value, isinstance() can detect a number value so returns True. Now we know the int() function can be used.


#7

Thanks ill try this now I'm starting to understand a lot better now.

just to be sure i understand this am i far of this is what i think they mean.

from numbers import number (this would import the numbers from the system running)
timecap = input (input given will become variable timecap)
if isinstance(timecap, Number): will get the number from timecap var or users entered number.

by the way your help has made a big difference to my code. :slight_smile:


#8

#!/usr/bin/env python3

from numbers import Number
import time
import os
print ("This script was designed to unlock AP limit locked routers it depends on aircrack-ng, reaver, and mkd5")
time.sleep(5)
interface = str(input("Enter wireless interface name: "))
print (interface)
os.system("sudo ifconfig {0}{1}".format(interface,"down"))
macchange = str(input("What is the mac address of target AP: "))
print (macchange)
os.system("sudo iwconfig {0}{1}".format(interface,"mode monitor")
#need a code for your are about to change mac address yes or no 
if prompt("You are about to change your mac address):
    os.system("sudo macchanger {0}{1}".format(interface ,macchange)
else:
    print ("Script will now contuine without changing mac address.")
os.system("sudo ifconfig {0}{1}".format(interface,"up")
print ("Airodump is going to start searching for target AP's.")
os.system("sudo airodump-ng {0:1}{1}".format("start",interface)
bssidname = str(input("What is the BSSID of the target: "))
chanwi = str(input("What Chanel is the AP on ?: "))
print ("Would you like to test if the AP is vul to the PixieDust WPS attack?.")
if y > n:
    os.system("sudo reaver {0:1}{1:1}{2:1}{3:1}{4:1}{5:1}{6:1}".format("-i",interface,"-b",bssidname,"-c",chanwi,"-K 1 -f -vvv")
elif n < y:
    os.system("reaver")
else:
    print ("Incorrect Option.")

print ("ESSID OF AP")
essidinput = str(input("What is the ESSID of the access point you are targeting ?: "))
if address == (essidinput):
    os.system("sudo macchanger {0}{1}".format(interface ,macchange)
elif address == no:
    os.system("sudo macchanger {0}{1}".format(interface ,macchange)
else:
    print ("Script will now contuine without changing mac address.")
time.sleep(2)
timeout = str(input("How much timeout do you want to give reaver ?: "))
time.sleep(2)
timecap = int(input("How much time in seconds for distance between pin atempts type [s]skip for defualt: "))
if timecap == s:
    os.system("sudo reaver {0}{1}".format("-i",interface)
elif timecap == 1 < 100:
    os.system("sudo reaver {0}{1}".format("-i",interface)
else: print ("You entered an incorrect value")

This is my code would u look at at and try to see where i went wrong basically the script will be designed unlock ap rate limited routers it will ask alot of input to store the vars for the command line options so when it eventually starts it knows what options to add there is many of these scripts but there writen in bash my idea was to convert the script to python that way i could get the script i need and also learn python killing 2 birds with one stone lol thanks for the help.


#9

To reiterate, input() returns a string, so we don't need to cast it to that type.

interface = input('...')

If expecting both string and numeric inputs, do not cast to int() without testing first, as demonstrated above.

There are a lot of errors in your code, not the least of which is unquoted strings and invalid conditional expressions. You will need to go through your code and correct all those errors if the program is ever going to run.

numbers.py is a module that contains the Number class. We need the class to be able to identify objects of the same class, otherwise we need to jump through a number of hoops just to determine if an input is a number.

This is where I hit a wall since I don't have the system to test your code so I'll have to hand this problem off to somebody with the wherewithal and the necessary system. Good luck and happy coding!


#10

Thanks ill have a go.

if condition:
x = true_value
else:
x = false_value

does x relate to any letter i enter or must it be a variable also must if and else both need x = or could i change that to say

if yes = true
if no = flase

another thing I'm confused about is

if y > n would this mean any letter enter that is greater then n will run the script or am i going about it all wrong much appreciated I'm also going to do a recap through the course section.

someone mentioned about def tags to define code would i advantage from adding these are would it just make things harder for me .

i understand that == would be if the user enter the exact word but unsure of setting them would this be correct way

craig(this is a var) == yes

if the input to the var watching craig was yes would this be true.

my new code i took a little out and added different if else and made the string input the first input is great but when i try a second input it fails.

!/usr/bin/env python3

from numbers import Number
import time
import os
print ("This script was designed to unlock AP limit locked routers it depends on aircrack-ng, reaver, and mkd5")
time.sleep(5)
interface = input("Enter wireless interface name: ")
print (interface)
os.system("sudo ifconfig {0:1}{1:1}".format(interface,"down")
targ = input("What is the mac address of target AP: ")
os.system("sudo ifconfig {0:1}{1:1}".format(interface,"up")
print ("Airodump is going to start searching for target AP's.")
os.system("sudo airodump-ng {0:1}{1}".format("start",interface)
bssidname = input("What is the BSSID of the target: ")
chanwi = input("What Chanel is the AP on ?: ")
print ("Would you like to test if the AP is vul to the PixieDust WPS attack?.")
if y = true:
os.system("sudo reaver {0:1}{1:1}{2:1}{3:1}{4:1}{5:1}{6:1}".format("-i",interface,"-b",bssidname,"-c",chanwi,"-K 1 -f -vvv")
elif n = false:
os.system("reaver")
else:
print ("Incorrect Option.")

print ("ESSID OF AP")
essidinput = input("What is the ESSID of the access point you are targeting ?: ")
if address == (essidinput):
os.system("sudo macchanger {0}{1}".format(interface ,macchange)
elif address == no:
os.system("sudo macchanger {0}{1}".format(interface ,macchange)
else:
print ("Script will now contuine without changing mac address.")
timeout = input("How much timeout do you want to give reaver ?: ")
timecap = input("How much time in seconds for distance between pin atempts type [n] for defualt: ")
if timecap = true:
os.system("sudo reaver {0}{1}".format("-i",interface)
elif n == false:
os.system("sudo reaver {0}{1}".format("-i",interface)
else: print ("You entered an incorrect value")

my error:

'/home/manjaro/Desktop/Programing/My Scripts/testscript.py' File "/home/manjaro/Desktop/Programing/My Scripts/testscript.py", line 11
targ = input("What is the mac address of target AP: ")
^
SyntaxError: invalid syntax


#11

Not sure I follow the question. Given a situation where we wish to assign a value to a variable in both cases, we would write the assignment as applies in each case. When the value being set is a boolean, we don't need an if-else. We can make a direct assignment of the boolean evaluation...

x = condition

will be either True, or False.

This assumes condition is a conditional expression such as, a > 100, b < 100, and so on.

from rand import randrange

a = randrange(200)
b = randrange(200)

c = a < 100 and b > 100

print c    # will be True or False

#12

thanks what is my problem here the ap (access point address) contains letters and numbers so i choose to go with only input but i get errors directed at the var.


#13

os.system("sudo ifconfig {0:1}{1:1}".format(interface,"down")
name = str(input("What is the name of the AP.")
os.system("sudo ifconfig {0:1}{1:1}".format(interface,"up")

error points to the var in command terminal ive tryed with many different vars and still the same thanks sorry to keep bothering you error: name = str(input("What is the name of the AP.")


#14

mtf why do u think my str(input(" is not working from this code

os.system("sudo ifconfig {0:1}{1:1}".format(interface,"down")
name = str(input("What is the name of the AP.")
os.system("sudo ifconfig {0:1}{1:1}".format(interface,"up")

is strange as other inputs don't seem to give any errors using same format above.

output from terminal:

name = str(input("What is the name of the AP.")
^
SyntaxError: invalid syntax


#15

I've already hit a wall with the question, as earlier expressed. That you insist upon writing,

str(input('...'))

even knowing it is unnecessary is rather disturbing. I'm taxed and must defer this topic to someone better informed. It's clear this program you are attempting to write is a spoofing program for hiding your system's ture MAC address and I do not wish to partake in this project any further.


#16

it is not it only uses software that is legal and freely obtained in no means is this to hide systems mac that's just an option it uses clones another mac of a mac already connected was the plan and it was only going be used as a test point for routers that belong to the user in no means was this code meant to offend anyone i tryed as u stated.

name = input('What is the name of the AP.')
^
SyntaxError: invalid syntax

I think someone should be able to code anything they want freely without anyone stoping there projects pentesting is part of security of code i am making this script becuase im studying cyber security and want it for my portfolio.


#17

Nobody is stopping you. I've only said that I hit a wall and don't know enough to be able to help any further. We need a more qualified programmer to step in. And I do agree that we need ways to test our own networks, but first we must bridge the knowledge gap, one that I haven't bridged yet. If I have network problems I call in a tech.


#18

yeah ill keep working on it sorry for the inconvenience ill go back through the course then get back to you later on could u give me some tips to study before attempering and yeah script is meant to be for good purpose but i do agree it could get into the wrong hands im going add a few warnings to it.