一些个人笔记,持续更新ing

python基础

基于《Python编程从入门到实践》一书
2.1~2.2 P18

message="hello python!!"
print(message)
message="test2"
print(message)

2.3
.title()首字母大写,中间字母转为小写
.upper()将字符串全部转为大写
.lower()将字符串字母全部转为小写
打印出制表符\t,打印出一个Tab建
换行同c一样,\n
.rstrip()删除右边的空白(right)
.lstrip()删除左边的空白(left)
.strip()删除两侧的空白
例:
print(“\tpython”)
先打印出一个Tab键再输出python
print(‘\tpython’)
同上输出相同,在python中单引号所见不为所得,与shell不同
2-3
name=“peter”
print(“Hello “+name.title()+” !”)
2-4

name="pEter"
print("Hello "+name.title()+" !")
print(name.lower())
print(name.title())
print(name.upper())

2-5
print(‘ones said ,"i am not best "’)

2.4 数字
加 +
减 -
乘 *
除 /
幂 2^3 表示为 2**3
注意:浮点数运算时包含的小数位可能不确定
例:0.1+0.2
结果为0.300000000000004
由于python中隐藏了变量类型,假设指定b=23,python无法识别将b作为字符串处理还是数字处理,在调用时使用str()函数,例:str(b)将b作为字符串进行输出。
注意: number=5 应用输出时str(b)
number=“5” 此时视number为字符串,输出不用str也可
a=123_456 输出时会自动忽略掉_,将a看作123456,整形可以无限大

第三章 第四章 列表 列表操作
列表:
例:a=[1,‘2’,‘ee’] 单引号代表字符串
访问时索引从零开始,a[0]=1,a[1]=‘2’
访问最后一个元素时可用-1,例:a[-1]=‘ee’,a[2].title()=‘Ee’

.append(新元素) 在结尾增添元素
.insert(number,‘new’) 把new作为新的元素插入到number的位置上,插入后number位置的元素为’new’
del a[1] 删除a列表第二个位置的元素
a.pop() 删除(弹出)a列表最后一个位置的元素,也可弹出任意位置的元素,须在()中指明
a.pop(0) 删除a列表中第一个元素
.remove() 若不知道列表中要删除的位置,但知道要删除元素的值用.remove()
a.remove(2) 删除a列表中值为2的元素,若有多个值为2的元素则删除下表最小的(即离表头最近的一个)
.sort() 对列表进行排序,排序时列表中不能同时有数字和字符串,若要排序将数字用单引号引起来当作字符串处理,此时数字排在前面,字母在后
.sort(reverse=Ture) 将列表进性倒序排序
sorted() 临时排序,例:print(soted(a)),将列表a临时排序输出,不会改变源列表
.reverse() 将列表倒叙打印,只是翻转原有的排列顺序
len(a) 确定列表a的长度,有几个元素就输出几

第四章 操作列表
for 循环
例: 遍历列表a
a=[1,2,3,4,5,6,7,8,4]
for loop in a: #将a中的第一个值1赋值给loop,进性第一次循环。。。。。
print(loop)
注意:for循环的循环结构中必须要首行缩进,而c语言中是用{ }
每次print后python都会自动换行
range() 产生一些数字
例:
for loop in range(0,7): 输出为数字0~6,当地一个参数为零时可以忽略简写为range(7)
print(loop) range中最后一个数字是不输出的,本例中不输出7
list() 创建列表,使用该函数可以将range产生的数字转换为列表,list(range(2,3))产生一个数字为2的列表
range(2,11,3) 产生数字2,5,8,最后的参数3为步长,即从2开始每次加三
min(b) 求b数字列表中最小值,b列表必须全为数字,或者全为字母
max(b) 最大
sum(b) 求和,b只能全为数字
列表解析:
a=[a**3 for a in range(1,101)] 产生1~100的三次方,此时for后没有:(冒号)
print(a)
切片:列表的一部分
a=[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
a[2:5] 输出为[9,16,25],输出下标2,3,4位置的元素
a[:3] 不指定起始位置默认从表头0位置开始
a[2:] 从第三个位置开始(包括)直到列表尾
a[-3:] 输出为[64,81,100] 负数索引返回离列表末尾相应距离的元素,
从距离表位3的位置开始输出直到表位
a[:-3] 从表头开始输出,直到距离表尾3的位置
要复制列表须创建一个包含整个列表的切片,a[:]从开头位置到表尾位置
注:不能将已知的a列表赋值给b即b=a,此时a与b列表为一个列表,类似c中的指针,即a,b指向一个列表。此时要用b=a[:]将列表a复制给b,此时a与b为两个列表。
元组:
用在小括号表示,a=(1,2,3) a[0]=1,a[1]=2,a[2]=3 不能修改元组中的值,但可以给元组重新赋值,用for循环遍历
第五章 if语句
if 判断语句:
执行1
else:
执行2
多重选择:
if 判断:
执行
elif 判断:
执行
elif 判断:
执行
else:
执行
与,或在C语言中用&& ,|| python中用and,or
检查特定值是否在列表中
例:a=[1,2,3,4,5,6,7]
2 in a 结果为True
‘2’ in a 结果为False
也可给变量赋值为False或True,此时成为布尔表达式,此时不需要加引号
if语句将在列表至少包含一个元素时返回Ture,列表为空时返回False
例:
if a:#此时a为列表

第六章 字典
b = {‘color’:3,5:‘ee’} 字典b中color对应数字3,b[color]为3
末尾若多加个逗号不影响表达,b = {‘color’:3,5:‘ee’,}
print(b[‘color’]) b[5]对应‘ee’
print(b[5])
其中color称为键,3称为值
添加键-值对
a[‘w’]=0 a为已知的字典,w为键,0为值
注意:键-值对的排列顺序与添加顺序不同,python不关心键-值对的添加顺序,只关心键和对之间的关联
要修改字典中的值已上为例,若要修改字典b中color对应的值,给其重新赋值即可。b[‘color’]=4
删除字典中键-值对同列表的一种方法相似,用del
例:del b[‘color’]
遍历字典:使用方法items()
例:
b = {‘color’:3,5:‘ee’}
for k,v in b.items(): 将字典b中键赋值给k,值赋值给v进行循环
print(“key:”+str(k)+‘\n’+‘value:’+str(v))
遍历字典中所有的键,使用方法keys(),遍历字典中所有的值可用方法values()
b = {‘color’:3,5:‘ee’}
for k in b.keys(): #若不加方法keys(),也会默认遍历键,输出不变
print(k)
注意:若存在两个相同的键,后一个定义的键会将前一个覆盖,即认为前一个键不存在
若要剔除大量重复元素调用集合set(), set(b.values())
列表中的元素也可以为字典,用len()求字典长度时,一个键-对长度为1

第七章 用户输入和while循环
input() 使用:a=input(“输出内容”),,先输出括号里的输出内容单引号双引号都可,再等待输入值,将输入的值赋值给a,使用input时所输入的值都将视为字符串,为此可使用函数int(),int(b)
将字符变量b转换为整型
% 求模,将两数相除返回余数
while 循环
例:
n=1
while n<=5:
print(n)
n+=1
continue 与break,,,与C语言中相同,continue跳出本次循环,break跳出整个循环
while循环删除列表中所有的特定值,remove仅可移除第一个
例:
while ‘要删除的元素’in 列表:
列表.remove()

第八章 函数
def 函数名(形参):
执行语句
函数名(实参) #调用
例:

def favorite_book(title):
    print("my favorite book is "+title.title())
favorite_book('the witcher')

关键字实参:在调用函数时在实参中指定形参的值
例:

def describe_pet(animal_type,pet_name):
    print('\n I have a '+animal_type+'.')
    print("my "+animal_type+"'s name is "+pet_name.title()+'.')
describe_pet(animal_type='hamster',pet_name='harry')		#此处为关键词实参此时已指定关键字,形参实参的位置不用固定,python会自动对其

默认值:
在定义函数时可指定形参的值
例:

def describe_pet(pet_name,animal_type='dog'):		##在此处默认了animal_type为'dog'
    print('\n I have a '+animal_type+'.')
    print("my "+animal_type+"'s name is "+pet_name.title()+'.')
describe_pet(pet_name='willie')		 ##在此处仅指定pet_name的值即可

注意:在调用时若仅含一个参数,会将该函数赋值给pet_name,所以在函数定义时形参的位置很重要,有默认值的形参要放在后面,给有默认值的形参赋值时会忽略掉默认值
返回值:
使用return返回,用法与C语言一样,不过不用定义函数返回的类型,统一用def。
使用return也可返回字典
让实参变成可选的:
没啥可讲的,就是把形参默认值改为空字符串,放在形参末尾,在配合使用if语句
if 默认字符串为空:
执行
else:
执行
例:

def build_person(first_name,lastname,age=''):
    person = {'first':first_name,
                'last':lastname}
    if age:
        person['age']=age
    return person
human=build_person('peter','park',age=27)  	#此时age=27覆盖了默认的age为空字符串也可写
print(human)				#‘27’,字符串27就覆盖了空字符串

参数传递列表:
例:

def greet_users(names):
    for name in names:
        msg = 'hello, ' + name.title() +'!'
        print(msg)
usernames = ['ha','ty','mar']
greet_users(usernames)

传递任意数量的实参:有时候预先不知道需要接收多少个实参,python允许函数从调用语句中收集任意数量的实参,此时使用*形参
例:
def make_pizza(t): #在C语言中表示地址,python中表示接收任意多的形参
print(t)
make_pizza(‘asda’)
make_pizza(‘sdf’,‘sdfsdfg’,‘jgh’)
使用任意数量的关键字实参:

def build_profile(first,last,**user):		##**user能够接收任意数量的键-值对
    profile = {} 
    profile['first_name'] = first
    profile['last_name'] = last
    for k,v in user.items():
        profile[k] = v
    return profile
user_profile = build_profile('a','b',location='partition',field='physics')	#注意:此时传递形参时
print(user_profile)				#键不用加引号

上例输出为{‘first_name’: ‘a’, ‘last_name’: ‘b’, ‘location’: ‘partition’, ‘field’: ‘physics’}
将函数储存在模块中:(类似将函数存储在头文件中)
test.py

import test2
test2.make_pizza(16,'pepperoni')	#注意使用时先写文件名.函数名
test2.make_pizza(12,'mushrooms','green peppers','extra cheese')

test2.py

def make_pizza(size,*t):
    print("\nMakeing a "+str(size)+"-inch pizza with following topping")
    for topping in t:
        print("-"+topping)

输出:

Makeing a 16-inch pizza with following topping
-pepperoni

Makeing a 12-inch pizza with following topping
-mushrooms
-green peppers
-extra cheese
使用as给函数指定别名:
from pizza import make_pizza as mp #此时使用make_pizza函数时简写为mp即可,不用加文件名
用as给模块指定别名:
import pizza as p #此时调用函数时写为p.make_pizza
若要导入一个模块中的所有函数使用*
from 模块名 import *

第九章 类
这一块不太好理解,结合P139,9.1的例子

class Dog():		##Dog约定为大写,但也可为小写
     def __init__(self,name,age):		##__init__两边必须为双下划线,形参self也必须位于最前列
        self.name = name		#变量前缀加self.
        self.age = age
     def sit(self):
        print(self.name.title() + "is now sitting ")
     def roll_over(self):
        print(self.name.title() + "rolled over")	#在类内调用参数就要加前缀self

my_dog = Dog('willie',6)	#将'while'传给name,6传给age
print("My dog's name is "+ my_dog.name.title() + '.')
print("My dog is "+ str(my_dog.age)+"years old.")
my_dog.sit()		#前写类名.类中的自定义函数
my_dog.roll_over()

练习:9-3 P142

class User():
    def __init__(self,first_name,last_name):
        self.first_name=first_name
        self.last_name=last_name
    def describe_user(self):
        print('your name is '+self.first_name.title()+' '+self.last_name.title())
    def greet_user(self):
        print('hello '+self.first_name+' '+self.last_name)
human=User('peter','park')
human.describe_user()
human.greet_user()

给属性指定默认值:

class Car():
    def __init__(self,make,model,years):		#默认的值不用传递形参
        self.make=make
        self.model=model
        self.years=years
        self.odometer_reading = 0		#在此处指定odomoter_reading的值为0(默认)
    def get_descriptive_name(self):
        long_name = str(self.years)+' ' + self.make+' '+self.model
        return long_name
    def read_odometer(self):
        print("This car has "+str(self.odometer_reading)+"miles on it")
my_new_car = Car('audi','a4','2016')
print(my_new_car.get_descriptive_name())
my_new_car.read_odometer()

修改此默认值时:
my_new_car.odometer_reading = 233
此时再使用my_new_car.read_odometer()函数进行输出时就修改了默认值
或者在类中新建一个方法用来修改默认值

def update_odometer(self,mileage):
	self.odometer_reading = mileage

my_new_car.update_odometer(23)	#调用该类中的函数来修改默认值,此处是增加

def increment_odometer(self,miles)
	self.odometer_reading +=miles
练习9-5
class User():
    def __init__(self,first_name,last_name):
        self.first_name=first_name
        self.last_name=last_name
        self.login_attempts=0
    def describe_user(self):
        print('your name is '+self.first_name.title()+' '+self.last_name.title())
    def greet_user(self):
        print('hello '+self.first_name+' '+self.last_name)
    def increment_login_attempts(self):
        self.login_attempts+=1
    def reset_login_attempts(self):
        self.login_attempts=0
    def pd(self):
        print(self.login_attempts)

human=User('peter','park')
human.pd()
human.increment_login_attempts()
human.pd()
human.reset_login_attempts()
human.pd()
继承:
class Car():
    def __init__(self,make,model,years):		#默认的值不用传递形参
        self.make=make
        self.model=model
        self.years=years
        self.odometer_reading = 0		#在此处指定odomoter_reading的值为0(默认)
    def get_descriptive_name(self):
        long_name = str(self.years)+' ' + self.make+' '+self.model
        return long_name
    def read_odometer(self):
        print("This car has "+str(self.odometer_reading)+"miles on it")
class ElectriCar(Car):			#定义子类时,父类必须包含在当前文件中,且位于子类前面
    def __init__(self,make,model,year):	#定义时()中为要调用的父类
        super().__init__(make,model,year)	#super()是一个特殊函数,帮助父类和子类关联让子类包含父类的所有属性,父类也称超类
my_tesla = ElectriCar('tesla','model s',2016)
print(my_tesla.get_descriptive_name())
重写父类:
class Car():
    def __init__(self,make,model,years):		#默认的值不用传递形参
        self.make=make
        self.model=model
        self.years=years
        self.odometer_reading = 0		#在此处指定odomoter_reading的值为0(默认)
    def get_descriptive_name(self):
        long_name = str(self.years)+' ' + self.make+' '+self.model
        return long_name
    def read_odometer(self):
        print("This car has "+str(self.odometer_reading)+"miles on it")
    def fill_gas_tank(self):	##这里定义了一个函数
        print("now is fill")
class ElectriCar(Car):
    def __init__(self,make,model,year):
        super().__init__(make,model,year)
    def fill_gas_tank(self):	##这里同样定义了一个同名的函数
        print("no gank")
my_tesla = ElectriCar('tesla','model s',2016)
print(my_tesla.get_descriptive_name())
my_tesla.get_descriptive_name()
my_tesla.fill_gas_tank()

此时调用子类的函数时时会忽略父类中同名的函数
导入类
from 模块名 import 类名
from 模块名 import 类名1,类名2
from 模块名 import * 导入所有类与函数

第十章 文件和异常
在notepad++中使用
with open(‘pi.txt’) as f:
s=f.read()
print(s)
即可读取pi.txt文本文档中的内容
才能读取
文件路径\反斜杠
‘w’ 写入模式,会清空以前原有的内容
‘r’ 读取模式
‘a’ 附加模式,追加
‘r+’ 能够读取和写入
省略默认读取模式
with open(‘pi.txt’,‘w’) as f:
f.write('just test!!!2 ')
.readlines() 从文件中读取每一行,并将其存储在一个列表中
例:(若pi.txt中内容为
1
2
3
4)

with open('pi.txt','r',encoding='UTF-8') as f:
    s= f.readlines()
    print(s)

输出为[‘1\n’, ‘2\n’, ‘3\n’, ‘4’]
存储数据 json(Java script object notation)
主要讲述两个函数,,,,,json.dump(),用来存储数据,使用方法为json.dump(数据,文件名)
json.load(文件名) 读取文件中的信息
例:

import json
number = [2,3,5,7,11,13]
filename = 'numbertest.json'
with open(filename,'w') as f:		#别忘了冒号:
    json.dump(number,f)

读取:

import json
filename = 'numbertest.json'
with open(filename) as f:
    a = json.load(f)
print(a)

机器学习等

.as_matrix()已改为.values 注:values没有括号

列表查找:
import numpy as np
a=np.array([1,2,3,4,5])
print(np.where(a<3))#查找小于3的元素的位置

(array([0, 1], dtype=int64),)

list.ravel()#ravel()方法将数组维度拉成一维数组
a=np.array([[1, 2], [2, 3]])
array([1, 2, 2, 3])

arr.reshape(m,-1) #改变维度为m行、d列 (-1表示列数自动计算,d= ab /m )
arr.reshape(-1,m) #改变维度为d行、m列 (-1表示行数自动计算,d= a
b /m )

a = np.array([[1, 1], [2, 2], [3, 3]])
array([[1, 1],
[2, 2],
[3, 3]])
np.insert(a, 1, 5)
array([1, 5, 1, …, 2, 3, 3])
np.insert(a, 1, 5, axis=1) # 在a中在第一列插入值为5的一列,aixs=1为列
array([[1, 5, 1],
[2, 5, 2],
[3, 5, 3]])

numpy.argmax(array, axis) 用于返回一个numpy数组中最大值的索引值。当一组中同时出现几个最大值时,返回第一个最大值的索引值。
例:
one_dim_array = np.array([1, 4, 5, 3, 7, 2, 6])
print(np.argmax(one_dim_array))
out:
4 # 最大值为7,索引为4

zip函数:
例:
a = [1, 2, 3]
b = [4, 5, 6]

a_b_zip = zip(a, b)  # 打包为元组的列表,而且元素个数与最短的列表一致
print("type of a_b_zip is %s" % type(a_b_zip))  # 输出zip函数的返回对象类型
a_b_zip = list(a_b_zip)  # 因为zip函数返回一个zip类型对象,所以需要转换为list类型
print(a_b_zip)

OUT:
type of a_b_zip is <class ‘zip’>
[(1, 4), (2, 5), (3, 6)] # 索引为0的组成一个元组

map函数:
map(function,iterable,…)
第一个参数接受一个函数名,后面的参数接受一个或多个可迭代的序列,返回的是一个集合。
del square(x):
return x ** 2

map(square,[1,2,3,4,5])

结果如下:
[1,4,9,16,25]

求10的0.065次方np.power(10,0.065)

reshape函数:
b = a.reshape(4,2)与b = np.reshape(a,4,2)等价

np.concatenate((a, b), axis=0)
axis=0 按照行拼接。
axis=1 按照列拼接。
a = np.array([[1, 2], [3, 4]])
b = np.array([[5, 6]]) #b是一个二维array
np.concatenate((a, b), axis=0) #按照行拼接
array([[1, 2],
[3, 4],
[5, 6]])

np.concatenate((a, b.T), axis=1) #按照列拼接
array([[1, 2, 5],
[3, 4, 6]])

unique():返回参数数组中所有不同的值,并按照从小到大排序
.index

assert就是一个断言函数。
什么是断言函数:不满足条件则直接触发异常,不必执行接下来的代码

split
参考:
一个参数

a="my name is zhangkang"
b="my\nname\nis\nzhangkang"
c="my\tname\tis\tzhangkang"

a=a.split()
b=b.split()
c=c.split()

print(a)
print(b)
print(c)

输出:
[‘my’, ‘name’, ‘is’, ‘zhangkang’]
[‘my’, ‘name’, ‘is’, ‘zhangkang’]
[‘my’, ‘name’, ‘is’, ‘zhangkang’]

俩参数:

d="my,name,is,zhangkang"
e="my;name;is;zhangkang"
f="my-name-is-zhangkang"

d=d.split(",")
e=e.split(";")
f=f.split("-")

print(d)
print(e)
print(f)

输出:
[‘my’, ‘name’, ‘is’, ‘zhangkang’]
[‘my’, ‘name’, ‘is’, ‘zhangkang’]
[‘my’, ‘name’, ‘is’, ‘zhangkang’]

仨参数:

a="My,name,is,zhangkang,and,I,am,a,student"
b1=a.split(",",1)
b2=a.split(",",2)
b8=a.split(",",8)
b9=a.split(",",9)

print(b1)
print(b2)
print(b8)
print(b9)

输出:
[‘My’, ‘name,is,zhangkang,and,I,am,a,student’]
[‘My’, ‘name’, ‘is,zhangkang,and,I,am,a,student’]
[‘My’, ‘name’, ‘is’, ‘zhangkang’, ‘and’, ‘I’, ‘am’, ‘a’, ‘student’]
[‘My’, ‘name’, ‘is’, ‘zhangkang’, ‘and’, ‘I’, ‘am’, ‘a’, ‘student’]

argsort函数返回的是数组值从小到大的索引值

conda

conda list #查看已经安装的库
conda info --env # 查看已经安装的环境 conda env list
conda --version # 查看conda版本 conda -V
conda activate xxx
conda create -n name python=x.x
conda remove -n name --all

ffmpeg –i xxx.mp4 –r 1 –y xxx_%06d.png,

tensorboard --logdir=./(当前路径)

isinstance的用法是用来判断一个量是否是相应的类型,接受的参数一个是对象加一种类型。示范代码如下:

a = 1

print(isinstance(a,int))

print(isinstance(a,float))

返回 True False

set nu
17,24 copy 25

安装包 pip install 包名 --user
卸载包pip uninstall 包名 -y
查看CPU状态: df -h

ssh -l name ip 端口

ffmpeg -i input.mp4 -vcodec mpeg4 output.mp4

ssh 到指定端口 ssh -p xx user@ip xx 为 端口号 user为用户名 ip为要登陆的ip

import cv2
print(cv2.version)

pip install --upgrade 要升级的包名

out = torch.unsqueeze(out,dim=0)

python输出百分比:
print(‘{:.0%}’.format(0.35)) # 0表示不保留小数
输出前面补零
print(‘{:0>2}:{:0>2}:{:0>2}’.format(hours, minutes, seconds))

ubuntu:111111

root,test:admin506

查看所用用户 compgen -u
cat /etc/passwd

math.jcb 求最大公约数

netstat -aptn #查看所有开启的端口
netstat -an

np.exp2(x) 计算所有x作为数组元素计算2 ** x
例如:
in:np.exp2([1,2,3,4])
out:array([ 2., 4., 8., 16.])

os._exit()会直接将python程序终止,之后的所有代码都不会继续执行。
sys.exit()会引发一个异常:SystemExit,如果这个异常没有被捕获,那么python解释器将会退出。如果有捕获此异常的代码,那么这些代码还是会执行。

池化中的ceil_mode=False当剩余的像素不足滤波器大小,是否仍对这些像素进行运算。

numpy 取消科学计数法和完整输出
import numpy as np

np.set_printoptions(suppress=True)

suppress=True 取消科学记数法

n, m = (int(x) for x in input().split(" "))

注意:
dp = [[2,2]*2]*3
dp = [[2,2]*2 for i in range(3)]
不等价

查找列表中的内容,设a为list
a.index(value) #value要查找的值,返回值所在的index

output.view(218, 178, 3) == output.view((218, 178, 3))

深度学习torch框架

太多了,需要自提把!
链接:https://pan.baidu.com/s/16mHLCTcN06eFsZ9tH2Qt-g
提取码:i15y

网络安全

With great power comes great responsibility.

su root #目录在kali下
su - root # 目录到root
exit #退出root
echo $SHELL #输出当前shell类型

apt update 的作用是从/etc/apt/sources.list文件中定义的源获取最新的软件列表,检查更新

apt upgrade #如果包有相互依赖性问题,此包不会升级

apt dist-upgrade # 不管,移除旧版,直接安装新版,有点风险,一般都会向下兼容

apt-get install maltego

IPv6地址中的%是网卡interdace的标识

kali设置静态ip
我这连的手机热点,ip不固定就不设置了,
方法如下:
vim /etc/network/interfaces中
iface lo inet loopback 下加入
iface eth0 inet static
address 192.168.x.x
netmask 255.255.255.0
getway 192.168.1.1

先关闭NetworkManger
systemctl stop NetworkManager
然后重启networking
systemctl restart networking # 一次不生效就执行两次

设置dns
vim /etc/resolv.conf
改 nameserver

配置临时ip 重启网络服务失效
ipconfig eth0 192.168.2.54
ipconfig eth0:1 192.168.1.44

配置sshd服务
vim /etc/ssh/sshd_config

重启ssh
systemctl restart ssh

Xshell
apt install lrasz
rz 上传文件
sz 下载文件

dig -x ip地址 知道ip地址反向查询域名
dig -x 114.114.114.114

dig txt chaos VERSION.BIND @ns3.dnsv4.com #查询dns服务器版本信息
whois 命令

注册信息:
whois.aliyun.com
站长之家 whois.chinaz.com

apt-get install maltego

路由跟踪:
traceroute baidu.com

arping 192.168.1.1

被动方式探测局域网中存活的机器,更隐秘
netdiscover -i eth0 -r 192.168.1.0/24

不发送任何数据包,仅嗅探
netdiscover -p

HPING3,也可用于DDOS攻击的实验
例如:
使用HPING3进行网站压力测试
www.qau.edu.cn
hping3 -c 1000 -d 120 -S -w 64 -p 80 --flood --rand-source www.qau.edu.cn

-c 1000 : 发送数据包的数量
-d 120 : 发送到目标机器的每个数据包的大小,单位是字节
-S :只发送SYN 数据包
-w :TCP窗口大小
-p :80 目的端口号
–flood:尽可能快的发送数据包,洪水攻击模式
–rand-source 使用随机性的源头ip地址,只是在局域网内伪造,通过路由器后还会还原成真实的ip

fping -g 192.168.1.0/24 -c 1 > fping.txt

nmap -sn 192.168.81.1/24
-sn 不进行端口扫描,只探测存活

TCP半连接扫描(不会留下记录)
nmap -sS 192.168.1.1 -p 80,81,21,443,500-600
-p 指定端口
不加-sS默认就是全连接扫描

nc扫描

scapy 是一个可以让用户发送,侦听和解析并伪装网络报文的python程序。

定制ARP协议:
ARP().display()
hwtype= 0x1 硬件类型
ptype= IPv4
hwlen= None
plen= None
op= who-has
hwsrc= 00:0c:29:ff:30:61 #源MAC
psrc= 192.168.81.141 # 源ip
hwdst= 00:00:00:00:00:00 # 目标MAC
pdst= 0.0.0.0 #目标ip

sr1函数:包含了发送数据包和接受数据包的功能

scapy定制ping
IP().display()
###[ IP ]###
version= 4 #版本
ihl= None # 首部长度
tos= 0x0 # 优先级与服务类型
len= None #总长度
id= 1 #标识符
flags= # 标志
frag= 0 #段偏移量
ttl= 64 # 生存时间
proto= hopopt #协议号
chksum= None # 首部校验和
src= 127.0.0.1 #源ip
dst= 127.0.0.1 #目标ip
\options\

ICMP().display()
###[ ICMP ]###
type= echo-request
code= 0
chksum= None
id= 0x0
seq= 0x0

sr1(IP(dst=“192.168.81.2”)/ICMP(),timeout=1)

定制SYN请求:

TCP().display()
###[ TCP ]###
sport= ftp_data # 源端口
dport= http # 目标端口
seq= 0 #32位序号
ack= 0 #32位确认序号
dataofs= None # 4位首部长度
reserved= 0
flags= S #标志位,紧急标志,有意义的应答标志,推,重置连接标志,同步序列号标志,完成发送数据标志:URG(紧急),ACK(确认),PSH(推送),RST(复位),SYN(同步),FIN(终止)
window= 8192 #窗口大小
chksum= None #16位校验和
urgptr= 0 #优先指针,紧急指针URG=1才有意义
options= [] # 选项

sr1(IP(dst=“192.168.81.2”)/TCP(flags=‘S’,dport=80),timeout=1)

僵尸扫描:可以不拿到肉鸡权限,只要对方的IPID是自增长的就可以
判断是否可以作为僵尸主机
nmap 192.168.81.0/24 -p1-1024 --script=ipidseq.nse
指定僵尸主机54,扫描主机2
namp 192.168.81.2 -sI 192.168.81.54 -p1-100

WireShark
(1)确定物理位置
(2)选择捕获接口
(3)使用捕获过滤器
(4)使用显示过滤器
(5)使用着色规则
(6)构建图标
(7)重组数据

混杂模式:
捕获所有网卡的数据,也有无关自己的

普通模式:
只捕获发送给本机的包

ip.addr == 110.242.68.4

arp:地址解析协议ip解析成mac

SSDP,DNS,QUIC,都是基于UDP传输层之上的协议

把ttl设置成1
echo ‘1’ > /proc/sys/net/ipv4/ip_default_ttl

换源:
deb http://mirrors.aliyun.com/kali kali-rolling main non-free contrib

deb http://mirrors.aliyun.com/kali-security/ kali-rolling main contrib non-free

deb-src http://mirrors.aliyun.com/kali-security/ kali-rolling main contrib non-free

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

JiYH

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值