ich entwickele weiterhin meinen konfigurierbaren TCP client,
aber bekomme beim Debuggen bzw. Ausführen folgendes:
IndentationError: unindent does not match any outer indentation level
Google hat im Wesentlichen nur stackoverflow.com ausgespuckt, und da geht es hauptsächlich
nur um die Einstellungen im Editor.
Vielleicht kann mir ja jemand helfen.
Danke schonmal im Vorraus.
P.S. Wie setze ich den Code in Python?
Code: Alles auswählen
######### TCP client 3.0
import socket
import threading
import os
import sys
import time
import urllib2
import urllib
import os.path
from os import *
from colorama import init
from colorama import Fore, Back, Style
init()
print (Back.CYAN + ' ###### Welcome! ######')
print (Style.RESET_ALL)
print ""
### Thread object: checking internet connection
def connected(host='http://google.com'):
try:
urllib.urlopen(host)
return True
except:
return False
# test
print( 'Connection established!' if connected() else 'No internet connection!' )
# User input
h = raw_input("Host > ")
h = socket.gethostbyname(h)
print "Target IP: ", h
while True:
try:
p = 80
p = int(p)
break
except ValueError:
print "No valid integer for port!"
print ('Checking data...')
time.sleep(0.5)
print (Style.RESET_ALL)
### Thread object: (BETA) Examining server's responses, not working yet
def handle_client(client_socket):
# Print what server says
request = client_server.recv(1024)
print "[*] Recieved: %s" % request
# socket object
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect((h, p))
client.sendall("GET / HTTP/1.1\r\nHost: google.com\r\n\r\n")
response = client.recv(4096)
print "Received data: " + (Fore.YELLOW)
print response
print (Style.RESET_ALL)
# path
mypath = path.join('/', 'home', 'crackhack', 'Schreibtisch')
chdir(mypath) # change directory(mypath)
if os.path.isfile('TCP data'):
chdir('TCP data')
rmdir('TCP data')
mypath2 = path.join('/', 'home', 'crackhack', 'Schreibtisch', 'TCP data')
chdir(mypath2)
fname = "Data.txt"
if os.path.isfile(fname):
print "File does exist at this time, overwriting it!"
os.remove("Data.txt")
myfile = file('Data.txt', 'w') # Making up new document
mystring = "Received data:\n" # String
myfile.write(response) # Writing string in file
myfile.close() # Close file
else:
print "No such file, creating new one"
myfile = file('Data.txt', 'w') # Making up new document
mystring = "Received data:\n" # String
myfile.write(response) # Writing string in file
myfile.close() # Close file
System: Xubuntu IDE: Geany