Mark Something
1. Linux下Unix时间戳转换:
[root@localhost ~]# date -d "2018/02/27 09:15" +%s 1519694100 [root@localhost ~]# date -d @1519694100 +'%Y-%m-%d %H:%M:%S' 2018-02-27 09:15:00 python获取文件时间:时间戳格式 os.path.getctime os.path.getmtime os.path.getatime时间戳格式转换: import datatime datetime.datetime.fromtimestamp('')
2. 探寻网段服务器的存活
(CPython) [root@localhost CPython]# nmap -n -sP -PE 192.168.40.0/24Starting Nmap 6.40 ( http://nmap.org ) at 2018-04-17 11:30 CST Nmap scan report for 192.168.40.1 Host is up (0.0050s latency). Nmap scan report for 192.168.40.10 Host is up (0.00031s latency). Nmap scan report for 192.168.40.12 Host is up (0.00024s latency). Nmap scan report for 192.168.40.20 Host is up (0.00031s latency). Nmap scan report for 192.168.40.21 Host is up (0.00025s latency). Nmap scan report for 192.168.40.22 Host is up (0.00033s latency). Nmap scan report for 192.168.40.100 Host is up (0.00030s latency). Nmap scan report for 192.168.40.110 Host is up (0.00027s latency). Nmap scan report for 192.168.40.111 Host is up (0.00027s latency). Nmap done: 256 IP addresses (9 hosts up) scanned in 1.53 seconds
3. nmap简单使用
In [2]: import nmap In [5]: nm = nmap.PortScanner() In [8]: nm.scan(hosts="192.168.40.0/24", arguments="-n -sP -PE") # 可用来探取存活设备的列表 Out[8]: {'nmap': {'command_line': 'nmap -oX - -n -sP -PE 192.168.40.0/24','scaninfo': {},'scanstats': {'downhosts': '247','elapsed': '1.48','timestr': 'Wed Apr 18 09:37:17 2018','totalhosts': '256','uphosts': '9'}},'scan': {'192.168.40.1': {'addresses': {'ipv4': '192.168.40.1'},'hostnames': [{'name': '', 'type': ''}],'status': {'reason': 'echo-reply', 'state': 'up'},'vendor': {}}, ... In [9]: nm.all_hosts() Out[9]: ['192.168.40.1','192.168.40.10','192.168.40.100','192.168.40.110','192.168.40.111','192.168.40.12','192.168.40.20','192.168.40.21','192.168.40.22']
4. telnet使用
In [12]: import telnetlib In [13]: tl = telnetlib.Telnet(host='192.168.10.10', port='16888', timeout=4) # 可以用来探寻远程端口,确定linux/windows主机 In [18]: tl.read_until(b'\n', timeout=5) Out[18]: b'SSH-2.0-OpenSSH_5.3\r\n'
5. python中的ssh登录模块
pexpect:启动子程序,使用正则表达式对程序输出做出特定响应,以此实现与其自动交互
In [26]: import pexpectIn [27]: pexpect.run(command="ls /tmp") Out[27]: b'systemd-private-15521997a49d4b519e338b4b2fcc63c4-mariadb.service-pmJpSb\r\n'In [29]: pexpect.run(command="ls /tmp", withexitstatus=1) # 输出命令及执行状态 Out[29]: (b'systemd-private-15521997a49d4b519e338b4b2fcc63c4-mariadb.service-pmJpSb\r\n',0)# SPAWN:启动子程序 In [30]: chk = pexpect.spawn('ls -l /tmp') In [33]: chk1 = pexpect.spawn('ls', ['-l','/tmp/'])
import pexpectdef login_ssh_passwd(port="",user="",host="",passwd=""):'''函数:用于实现pexepect实现ssh的自动化用户密码登录'''# print 'ssh -p %s %s@%s' % (port,user, host)if port and user and host and passwd:ssh = pexpect.spawn('ssh -p %s %s@%s' % (port,user, host))i = ssh.expect(['password:', 'continue connecting (yes/no)?'], timeout=5)if i == 0 :ssh.sendline(passwd)elif i == 1:ssh.sendline('yes\n')ssh.expect('password: ')ssh.sendline(passwd)index = ssh.expect (["#", pexpect.EOF, pexpect.TIMEOUT])if index == 0:print "logging in as root!"ssh.interact()elif index == 1:print "logging process exit!"elif index == 2:print "logging timeout exit"else:print "Parameter error!"def login_ssh_key(keyfile="",user="",host="",port=""):'''函数:用于实现pexepect实现ssh的自动化密钥登录'''if port and user and host and keyfile:ssh = pexpect.spawn('ssh -i %s -p %s %s@%s' % (keyfile,port,user, host))i = ssh.expect( [pexpect.TIMEOUT,'continue connecting (yes/no)?'], timeout=2)# print '...................................',0if i == 1:ssh.sendline('yes\n')index = ssh.expect (["#", pexpect.EOF, pexpect.TIMEOUT])else:index = ssh.expect (["#", pexpect.EOF, pexpect.TIMEOUT])if index == 0:print "logging in as root!"ssh.interact()elif index == 1:print "logging process exit!"elif index == 2:print "logging timeout exit"else:print "Parameter error!"
paramiko:基于python实现的SSH远程安全连接,用于SSH远程执行命令、文件传输等功能的ssh客户端模块
转载于:https://www.cnblogs.com/aaronzmia/p/8477062.html
Mark Something相关推荐
- opencv——pcb上寻找mark点(拟合椭圆的方法)
#include "stdafx.h" // FitCircle.cpp : 定义控制台应用程序的入口 #include "cv.h" #include &qu ...
- IOS笔记 #pragma mark的用法
简单的来说就是为了方便查找和导航代码用的. 下面举例如何快速的定位到我已经标识过的代码. #pragma mark 播放节拍器 - (void) Run:(NSNumber *)tick { //.. ...
- 两个点 定位_深圳Mark点定位的一般原理与步骤
Mark点定位主要应用于被测物体幅面巨大,远远超过相机视野时(一般在检测PCB,或者大料盘).相比于传统的检测方法,Mark点定位可以大大提高检测效率,但是因为考虑到被检物体冷热缩放.刚体形变等原因, ...
- idea resources目录_最全八种IDEA目录类型标注:Mark Dir as Sources/Resources Root
IDEA中Mark Directory as对项目的任意目录进行以下八种目录类型标注,这个知识点很重要,必须Get到. 1.Sources Root 标注源代码文件夹 (or source folde ...
- 读书笔记:《HTML5开发手册》--figure、time、details、mark
周日继续读<HTML5开发手册>,并进行Demo练习,今天主要学习四个HTML5新增的元素:figure.time.details.mark. 不学不知道,原来这些平时不注意的元素都有着很 ...
- 文本编辑BOM标记(Byte Order Mark)
微软的自带记事本程序notepad.exe会给UTF-8编码的文件头加入三个隐藏的字节(即BOM).这是一种很愚蠢的做法.就是为了让编辑器不去猜测文件本身是ASCII码还是UTF-8. 什么是BOM ...
- Mark: Fisrt note with live writer
mark !! 转载于:https://www.cnblogs.com/zqingnn/archive/2011/01/04/1925544.html
- 聊聊 #pragma 和 // MARK:
我去,就这两个东西还要讲?是OC或Swift开发人员都知道是怎么回事好吗?不就是用来标记和分组代码的吗?难道还有别的装逼技能? 当然,其实问大部分人说这两个是什么作用,或者是除了这两个还知道什么的情况 ...
- Keil错误fatal error: UTF-16 (LE) byte order mark detected
错误提示:fatal error: UTF-16 (LE) byte order mark detected '..\blinky.c' but encoding is not supported 原 ...
- golang 警告提示 Error string should not be capitalized or end with punctuation mark
Error string should not be capitalized or end with punctuation mark 错误字符串不应该大写或以标点符号结束 当我们在 Golang 中 ...
最新文章
- PL/SQL三种集合类型的比较
- 《ArcGIS Runtime SDK for Android开发笔记》——(6)、基于Android Studio的ArcGIS Android工程结构解析...
- revit如何根据坐标进行画线_护肤干货丨抗衰老的护肤品有哪些?如何根据成分进行挑选?(1)...
- 什么是闭包,我的理解
- Linux编译程序时加-I指定头文件位置
- 红旗linux培训文档,Linux基本应用培训-红旗Linux.ppt
- java编程式事务_Spring编程式和声明式事务实例讲解
- scala ip转换器
- 简单java游戏代码_Java经典小游戏——贪吃蛇简单实现(附源码)
- Linux配置静态IP 详细截图
- ThinkPHP商城系统与外部系统用户互通,集成UCenter
- ajax怎么回调函数,ajax使用回调函数的例子(原生代码和jquery代码)
- python 四象限图_方法:高效处理工作的四象限图
- daimayuan每日一题#851 Good Permutations
- Simulation?Emulation?模拟?仿真?
- fixed bug: is not eligible for getting processed by all BeanPostProcessors
- 2018 | 七月日记
- 个人用户永久免费,可自动升级版Excel插件,使用VSTO开发,Excel催化剂功能第11波-快速批量插入图片...
- 一文搞懂电工配电二线制、三线制、四线制
- 如何把char类型的数字字符转换成int类型