• shell和python批量ping


    #####baidu ip #######
    220.181.38.148
    220.181.38.133
    192.168.1.10

    #!/usr/bin/python
    # -*- coding:utf-8 -*-
    import os
    import sys,re
    import subprocess

    #定义正则,排除以#开头的行

    res = r'([^#])'

    #判断文件是否存在
    if os.path.isfile('/root/iplist.txt'):

    #打开文件
    with open('/root/iplist.txt', 'r') as f:
    for line in f.readlines():

    #开始匹配
    m = re.match(res,line)
    if m:

    #匹配到就执行ping操作
    tt = subprocess.call('ping -c 10 -w 10 %s' %line, stdout=subprocess.PIPE,shell=True)

    if tt :
    print ('%s' %line.rstrip(),",","down",",",1)
    else:
    print ('%s' %line.rstrip(),",","up",",",0)

    #!/bin/bash
    for i in `cat iplist.txt |grep -v "#" `

    do

    #echo $i
    ping -c 10 -w 10 $i &> /dev/null
    if [ "$?" == "0" ];then

    echo $i","up","0

    else

    echo $i","down","1

    fi

    #ping -c 10 $i |grep loss|awk '{print $6}'|awk -F "%" '{print $1}'`
    #if [ $ping -eq 100 ];then
    #echo $i,up
    #else
    #echo $i,down
    #fi

    done

  • 相关阅读:
    TC79
    SQL TUNNING
    Oracle PLSQL
    DB String Split sample
    dw websites
    Load xlsx in a folder to RDBMS table with Talend
    Reading WebSites
    SQOOP Load Data from Oracle to Hive Table
    dotnet use regex two samples
    Excel scientific notation issue
  • 原文地址:https://www.cnblogs.com/chengxuyonghu/p/13600849.html
Copyright © 2020-2023  润新知