oceans吧 关注:11贴子:160
  • 13回复贴,共1
生活充满柴米油盐酱醋茶


IP属地:上海1楼2016-06-23 15:03回复
    但也要努力有诗和远方


    IP属地:上海2楼2016-06-23 15:11
    回复
      在这里做学习记录是不是不大好hahah


      IP属地:上海3楼2016-09-03 16:19
      回复
        python-准备开发环境
        mac上预装了2.7.10基本是足够了,在终端执行
        # python //可以进入python,并且会直接显示版本号并且交互程序运行
        Python 2.7.10 (default, Oct 23 2015, 19:19:21)
        [GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
        Type "help", "copyright", "credits" or "license" for more information.
        >>>print "hello world"
        hello world
        >>>exit() //这是退出python的命令
        咳咳,避免不了的第一个helloworld.py
        # echo print \"Hello world\">helloworld.py
        # chmod 777 helloword.py
        # python helloworld.py
        hello world


        IP属地:上海4楼2016-09-03 16:36
        回复
          当然了,先看语法呗
          变量的知识
          >>> number=12 //定义一个整形变量
          >>> string=abc //定义一个字符型变量---不能忘记双引号啊
          Traceback (most recent call last):
          File "<stdin>", line 1, in <module>
          NameError: name 'abc' is not defined
          >>> string="abc"
          >>> print "the number is" +number+ "the name is" +string //打印出来---报错了
          Traceback (most recent call last):
          File "<stdin>", line 1, in <module>
          TypeError: cannot concatenate 'str' and 'int' objects
          >>> type(number)
          <type 'int'>
          >>> type(string) ---变量类型不一样,不能print
          <type 'str'>
          >>> print "the number is" +number+ "the name is" +int(string) //将字符型转换成整形--报错了,不能这么转换
          Traceback (most recent call last):
          File "<stdin>", line 1, in <module>
          TypeError: cannot concatenate 'str' and 'int' objects
          >>> print "the number is" +str(number)+ "the name is" +string //将整形转换成字符型 --可以
          the number is12the name isabc
          >>> print "the number is " +str(number)+ " the name is " +string // 让他展示的漂亮点
          the number is 12 the name is abc


          IP属地:上海5楼2016-09-03 16:48
          回复
            决定了,晚上再继续


            IP属地:上海7楼2016-09-03 16:59
            回复
              list
              >>> list1=[21] //定义一个list
              >>> list1.append(32) //向list里加数据
              >>> list1.append(29)
              >>> list1.append(2)
              >>> print list1
              [21, 32, 29, 2]
              >>> list1.sort() //给list排序
              >>> print list1
              [2, 21, 29, 32]
              >>> poo=list1.index(32) //查找元素32,得到元素的位置的值
              >>> print poo
              3
              >>> list1.remove(29) //移除元素29
              >>> print list1
              [2, 21, 32]
              >>> leng=len(list1) //查看list的长度
              >>> print leng
              3
              >>>


              IP属地:上海9楼2016-09-04 16:07
              回复
                关于条件选择
                >>> if("FreeFloat Ftp Server (Version 1.00)" in an): //接上面的,当语句没结束时用:
                ... print "[+] FreeFloat FTP Server is vulnerable" //⚠️要有空格在print前,不然交互器就不能换行了,一般时候用\换行也行
                ... else:
                ... print "[-] FTP Server is not vulnerable"
                ...
                [-] FTP Server is not vulnerable //因为socket还要再研究下ip和port所以只能返回这种结果了


                IP属地:上海11楼2016-09-04 17:08
                回复
                  异常处理
                  >>> try:
                  ... print "[+] 12/0 = "+str(1337/0) //➗0错
                  ... except Exception,error: //将Exception的内容放到error里面
                  ... print "[-] ERROR ="+str(error) //打印报错
                  ...
                  [-] ERROR =integer division or modulo by zero
                  >>> import socket
                  >>> socket.setdefaulttimeout(2) //设置超时时间
                  >>> s=socket.socket()
                  >>> try:
                  ... s.connect(("192.168.95.149",21))
                  ... except Exception,error:
                  ... print "[-] Error : "+str(error)
                  ...
                  [-] Error : timed out


                  IP属地:上海12楼2016-09-04 18:28
                  回复
                    函数---找了个编辑器sublime
                    import socket
                    def retBanner(ip,port): //函数
                    try:
                    socket.setdeffaulttimeout(2)
                    s=socket.socket()
                    s.connect((ip,port))
                    banner = s.recv(1024)
                    return bunner
                    except:
                    return
                    def main(): //main
                    ip1 = 'http://www.sina.com.cn'
                    ip2 = '192.168.95.149'
                    port1 = 80
                    port2 = 21
                    banner1 = retBanner(ip1,påort1)
                    print "[+]" + str(ip1) + ": " + str(banner1)
                    banner2 = retBanner(ip2,port2)
                    print "[+]" + str(ip2) + ": " + str(banner2)
                    if __name__ == '__main__':
                    main()
                    -------//在终端执行
                    # python hello.py
                    [+]http://www.sina.com.cn: None
                    [+]192.168.95.149: None


                    IP属地:上海13楼2016-09-04 19:07
                    收起回复
                      迭代哟 --还是用sublime赞
                      def checkname(name):
                      if("king" in name):
                      print "hi,"+name+",you are king Fimily"
                      else:
                      print "i'm sorry,"+name+",you make an error"
                      return
                      def checkage(age):
                      if(age==24):
                      print "hi,24 girl"
                      else:
                      print "i'm sorry,you are "+str(age)+",you make an error"
                      return
                      def main():
                      namelist = ['king3','king2','rong']
                      agelist = [24,20,24]
                      for x in range(len(namelist)): //迭代在此!!
                      checkname(namelist[x])
                      checkage(agelist[x])
                      if __name__ == '__main__': //主函数在此
                      main()


                      IP属地:上海14楼2016-09-04 21:24
                      回复
                        # python for.py
                        hi,king3,you are king Fimily
                        hi,24 girl
                        hi,king2,you are king Fimily
                        i'm sorry,you are 20,you make an error
                        i'm sorry,rong,you make an error
                        hi,24 girl
                        //这是运行结果,运行三次,判断家族和年龄


                        IP属地:上海15楼2016-09-04 21:26
                        回复
                          python模块sys
                          使用sublime
                          import sys //加载模块
                          if len(sys.argv)==2: //长度=2 即sys.argv[0],sys.argv[1]这两个元素其中sys.argv[0]元素师python脚本名称
                          filename = sys.argv[1] //将第二个参数赋予变量filename
                          print "[+] Reading Vulnerabilities from : "+filename
                          # python syss.py names.txt
                          [+] Reading Vulnerabilities from : names.txtå


                          IP属地:上海17楼2016-09-05 22:23
                          回复