【问题标题】:Python, I am coding a remote shell maker and keep on running into syntax errorsPython,我正在编写一个远程 shell 制造商并不断遇到语法错误
【发布时间】:2018-09-24 17:39:45
【问题描述】:
import os
os.system("touch shellback.py")
a = raw_input("IP of The Listener(you)> ")
print "Set ip to "+ a +""
file = open("shellbackdoor.py", "a")
file.write("from socket import *\n")
file.write("HOST = '"+ a +"'\n");
file.close()
file = open("shellback.py", "a")
file.write("PORT = 443\n")
print "You might to to port forward your router to the port 443"
file.write("s = socket(AF_INET, SOCK_STREAM)\n")
file.write("s.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)\n")
file.write("s.bind((HOST, PORT))\n")
file.write("print 'Listening on "+ a +":%s' % str(PORT)\n")
file.write("s.listen(10)\n")
file.write("conn, addr = s.accept()\n")
file.write("print 'Connected by', addr\n")
file.write("data = conn.recv(1024)\n")
file.write("while 1:\n")
file.write("     command = raw_input("> ")")
file.write("     conn.send(command)\n")
file.write("     if command == "quit":\n")
file.write("          break\n")
file.write("     data = conn.recv(1024)\n")
file.write("     print data\n")
file.write("conn.close()\n")

我一直在遇到语法错误

file.write("     if command == "quit":\n")

不知道为什么

上面用了两行

file.write("     command = raw_input("Insert your command or quit>")")

但在我将其更改为之后它停止了错误

file.write("     command = raw_input("> ")")

【问题讨论】:

    标签: python python-2.7 shell syntax-error


    【解决方案1】:

    你做得对。但是您需要像我在下面显示的那样转义双引号

    代码中的一行:

    file.write("     if command == "quit":\n")
    

    固定线路

    file.write("     if command == \"quit\":\n")
    

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 2020-03-04
      • 1970-01-01
      • 2020-12-31
      • 1970-01-01
      • 2017-02-22
      • 2022-10-15
      • 1970-01-01
      • 2016-02-05
      • 2018-10-19
      相关资源
      最近更新 更多