我正在尝试从我的家用电脑上使用denyhosts,现在它已经阻止了我的ip地址并输入了/etc/hosts.deny.

现在我的ip不是静态的,它每周都会打开,所以我可以在hosts.allow中修复ip.

我尝试从/etc/hosts.deny手动删除该ip,并在5分钟后再次添加该地址.

如何从denyhosts手动删除被阻止的IP地址

CentOS的

您实际上需要停止denyhosts,然后从其他6个文件中删除有问题的条目并重新启动它.
受影响的文件是:

> / var / lib / denyhosts / hosts
> / var / lib / denyhosts / hosts-restricted
> / var / lib / denyhosts / hosts-root
> / var / lib / denyhosts / hosts-valid
> / var / lib / denyhosts / users-hosts
> /etc/hosts.deny

这是我创建的Python脚本,用于执行相同的操作 – 用法是sudo ./unban.py ip-goes-here

#!/usr/bin/python
import re
import sys
import subprocess
from subprocess import call
import tempfile
import logging
import os
import datetime
import re 

#http://daniweb.com/code/snippet216475.html
#http://www.doughellmann.com/PyMOTW/tempfile/
#http://www.daniweb.com/forums/thread73705.html
#http://pbe.lightbird.net/tempfile-module.html
#http://www.palewire.com/posts/2008/04/07/python-recipe-open-multiple-files-search-for-matches count-your-hits-on-the-fly/
#http://docs.python.org/library/logging.html
#http://docs.python.org/library/subprocess.html#module-subprocess
#http://docs.python.org/tutorial/errors.html#handling-exceptions

#You actually need to stop denyhosts and remove the offending entry from 5 other files. '/var/lib/denyhosts/hosts','/var/lib/denyhosts/hosts-restricted','/var/lib/denyhosts/hosts-root','/var/lib/denyhosts/hosts-valid','/var/lib/denyhosts/users-hosts','/etc/hosts.deny'
#Here is a link to a ruby script to do so,http://robotplaysguitar.com/2009/10/30/remove-an-ip-banned-by-denyhosts/
#Or here is a Python script I created to do the same thing -- usage is sudo python ./unban.py ip-goes-here



def returnTime():
  dt = datetime.datetime.Now()
  str(dt)
  return dt.strftime("%Y%m%d_%H:%M:%s")

#########################################
#  Uncomment these below for debugging  #
#########################################
#print sys.argv[1]
#print len(sys.argv)
#########################################  
#  Change these values for logging      #
#########################################
LOG_FILENAME = './unban.log'
logging.basicConfig(filename=LOG_FILENAME,level=logging.DEBUG)
logging.debug("---------------" + returnTime() + "----------------------") # initialize debugging

denyhosts=("/etc/init.d/denyhosts")
start="start"
stop="stop"
denyhosts_files=['/var/lib/denyhosts/hosts','/var/lib/denyhosts/users-invalid','/etc/hosts.deny']

if len(sys.argv) <> 2:
  print "Wrong number of args"
  print "Usage: sudo python ./unban.py ip"
else:
  if subprocess.call([denyhosts,stop]) == 0:
    logging.debug("/etc/init.d/denyhosts stopped at:\t" + returnTime())
    print "/etc/init.d/denyhosts stopped"
  else:
    print "error stopping denyhosts..."
    logging.debug("Error stopping /etc/init.d/denyhosts\t" + returnTime())
    sys.exit("bork =(")

  ip = sys.argv[1]

  for f in denyhosts_files:
    tf = tempfile.NamedTemporaryFile(delete=False)
    print "Temp Filename is:" + tf.name + " Real file name is: " + f

    try:
      text = open(f,"r")
      data_list = text.readlines()  
      logging.debug("File: "+ f + " is being worked on.\t"+returnTime())
    except IOError as (errno,strerror):
      print "I/O error({0}): {1}".format(errno,strerror)

    for line in data_list:  
      if re.search(ip,line):
        print line    
        # just do nothing here -- because we are writing all the good IP's to a file!  genius! 
        logging.debug("Deleting ip: " + ip + " because we found a match.\t" + returnTime())
      else:
        tf.write(line)
    ####
    #  Close the temporary file
    ####                 
    try:
      text.close()
      tf.close()
      logging.debug('This is where the text file: ' + tf.name + ' is closed.\t' + returnTime() )
    except OSError:  
      print "OS error({0}): {1}".format(errno,strerror)
    except:
      print "Unexpected error:",sys.exc_info()[0] 

    try:
      os.rename(f,f+"_tmp") 
    except OSError:
      print "OS error({0}): {1}".format(errno,sys.exc_info()[0]
    try:
      os.chmod(f+"_tmp",0644) # this makes the temp file 644
    except OSError:
      print "OS error({0}): {1}".format(errno,sys.exc_info()[0]  
    try:
      os.rename(tf.name,f)  
    except OSError:
      print "OS error({0}): {1}".format(errno,sys.exc_info()[0]
    try:    
      os.chmod(f,0644) # this make the newly edited file 0644
      logging.debug("File: "+ f + " has been renamed. - " + returnTime())
    except OSError:
      print "OS error({0}): {1}".format(errno,sys.exc_info()[0]



###
#  Clean up and restart denyhosts
###  
if subprocess.call([denyhosts,start]) == 0:
  print "/etc/init.d/denyhosts Started"
  logging.debug("/etc/init.d/denyhosts succesfully restarted!\t" + returnTime()) 
else:
  print "There was an error starting /etc/init.d/denyhosts...\t"
  logging.debug("/etc/init.d/denyhosts did not restart successfully \t" + returnTime())

centos – 如何从denyhosts删除IP地址的更多相关文章

  1. ios中的.dylib和.a lib有什么区别?

    我知道Objectivec中的编译和运行时是什么,但是我想知道是什么画了这两个库之间的界限?他们的目的是什么,除了陈述一个是静态的而另一个是动态的?我们何时需要一个而不是另一个?

  2. xamarin.ios – ShareKit与MonoTouch如何?

    有人可以验证ShareKit实际上是否可用于MonoTouch并指导我完成使其工作所需的步骤?解决方法您首先从getsharekit.com下载还是使用ShareKit2.0?

  3. ios – 200在xcode 7中生成DSMM警告

    解决方法我有同样的问题.Facebook表示他们已经意识到这一点并且不是高优先级,因为它不会影响应用程序.我回退到4.7.1警告问题不再存在.我不认为它会被拒绝但不能确定.

  4. ios – iPhone崩溃日志不能正确地符号化并且是双重间隔的

    任何建议超过欢迎.谢谢.解决方法当这件事发生在我身上时,它只是我通过电子邮件收到的日志.如果我记得,至少有一些是在.msg文件中,我不得不把它们拿出来.它可能是Exchange编码更改.如果你显示不可见的字符,你可能会看到每个字符之间的东西.您可以找到并替换它们以删除它们或更改编辑器中的编码.

  5. xamarin.ios – Facebook iOS SDK:应用程序在启动时找不到“找不到符号:_ACFacebookAppIdKey.”仅在iOS 5中崩溃

    解决方法这是一个已修复的knownbug.目前唯一已知的解决方法是使用较旧版本的FacebookSDK.

  6. ios – Xcode 7 beta 2:LaunchScreen.storyboard无法打开文档

    我在两个不同的Mac(iMac和MacBookpro)上收到这个错误.不知道为什么人们不能再现它,但我需要一些帮助.在运行XX优胜美地10.10.4的Mac上运行Xcode7beta2(15六月’15).甚至无法编译和运行我的项目..我从创建菜单创建了一个视图应用程序项目,就是这样.编辑:我试图删除并重新添加storyboard文件(也可以打开Main.storyboard插件),我仍然得到相同的

  7. osx – 无法创建目录/ var / teamsserver

    OpenSSH_6.2p2,OSSLShim0.9.8r8Dec2011debug1:Readingconfigurationdata/etc/ssh_configdebug1:/etc/ssh_configline20:Applyingoptionsfor*debug1:Connectingto1.2.3.4[1.2.3.4]portPORT.debug1:Connectionestablished.Couldnotcreatedirectory‘/var/teamsserver/.ssh’.debug

  8. ios – 如何在Xcode 4.5中完成代码签名

    解决方法事实证明,从AppStore升级XCode并不会自动升级所有内容.转到首选项/下载,并确保安装最新的命令行工具.

  9. ios – 为具有多个目标和不同平台的项目编写Podfile

    如何让CocoaPods成功整合到我的项目和iOS/Mac目标?我已经阅读了Podfile文档,但发现它在这方面缺乏.解决方法得到它了!从我的每个目标和运行的pod安装中删除libPods-xxxx.a文件,再次执行了我的目标集成.

  10. xcode7 – 谁在创建文件“/private/var/tmp/Untitled-*.uicatalog”?

    我正在调查为什么TeamCity构建代理程序用完了磁盘,并且在/private/var/tmp中找到了超过11,000个文件,它们都以Untitled-.uicatalog行命名.每个文件至少0.6MB.总磁盘占用空间约为4GB.这些文件可以追溯到几个月,所以他们能够重新启动.谁在创造他们?Xcode在编译至少有一个图像的xcassets目录时创建这些目录.我可以删除它们吗?

随机推荐

  1. 在airgapped(离线)CentOS 6系统上安装yum软件包

    我有一个CentOS6系统,出于安全考虑,它已经被空气泄漏.它可能从未连接到互联网,如果有,它很长时间没有更新.我想将所有.rpm软件包放在一个驱动器上,这样它们就可以脱机安装而无需查询互联网.但是,我在测试VM上遇到的问题是,即使指定了本地路径,yum仍然会挂起并尝试从在线存储库进行更新.另外,有没有办法使用yum-utils/yumdownloader轻松获取该包的所有依赖项和所有依赖项?目前

  2. centos – 命名在日志旋转后停止记录到rsyslog

    CentOS6.2,绑定9.7.3,rsyslog4.6.2我最近设置了一个服务器,我注意到在日志轮换后,named已停止记录到/var/log/messages.我认为这很奇怪,因为所有日志记录都是通过rsyslog进行的,并且named不会直接写入日志文件.这更奇怪,因为我在更新区域文件后命名了HUPed,但它仍然没有记录.在我停止并重新启动命名后,记录恢复.这里发生了什么?

  3. centos – 显示错误的磁盘大小

    对于其中一个磁盘,Df-h在我的服务器上显示错误的空白区域:Cpanel表明它只有34GB免费,但还有更多.几分钟前,我删除了超过80GB的日志文件.所以,我确信它完全错了.fdisk-l/dev/sda2也显示错误:如果没有格式化,我该怎么做才能解决这个问题?并且打开文件描述符就是它需要使用才能做到这一点.所以…使用“lsof”并查找已删除的文件.重新启动写入日志文件的服务,你很可能会看到空间可用.

  4. 如何在centos 6.9上安装docker-ce 17?

    我目前正在尝试在centOS6.9服务器上安装docker-ce17,但是,当运行yuminstalldocker-ce时,我收到以下错误:如果我用跳过的标志运行它我仍然得到相同的消息,有没有人知道这方面的方法?

  5. centos – 闲置工作站的异常负载平均值

    我有一个新的工作站,具有不寻常的高负载平均值.机器规格是:>至强cpu>256GB的RAM>4x512GBSSD连接到LSI2108RAID控制器我从livecd安装了CentOS6.564位,配置了分区,网络,用户/组,并安装了一些软件,如开发工具和MATLAB.在启动几分钟后,工作站负载平均值的值介于0.5到0.9之间.但它没有做任何事情.因此我无法理解为什么负载平均值如此之高.你能帮我诊断一下这个问题吗?

  6. centos – Cryptsetup luks – 检查内核是否支持aes-xts-plain64密码

    我在CentOS5上使用cryptsetupluks加密加密了一堆硬盘.一切都很好,直到我将系统升级到CentOS6.现在我再也无法安装磁盘了.使用我的关键短语装载:我收到此错误:在/var/log/messages中:有关如何装载的任何想法?找到解决方案问题是驱动器使用大约512个字符长的交互式关键短语加密.出于某种原因,CentOS6中的新内核模块在由旧版本创建时无法正确读取512个字符的加密密钥.似乎只会影响内核或cryptsetup的不同版本,因为在同一系统上创建和打开时,512字符的密钥将起作用

  7. centos – 大量ssh登录尝试

    22个我今天登录CentOS盒找到以下内容这是过去3天内的11次登录尝试.WTF?请注意,这是我从我的提供商处获得的全新IP,该盒子是全新的.我还没有发布任何关于此框的内容.为什么我会进行如此大量的登录尝试?是某种IP/端口扫描?基本上有4名匪徒,其中2名来自中国,1名来自香港,1名来自Verizon.这只发生在SSH上.HTTP上没有问题.我应该将罪魁祸首子网路由吗?你们有什么建议?

  8. centos – kswap使用100%的CPU,即使有100GB的RAM也可用

    >Linux内核是否应该足够智能,只需从内存中清除旧缓存页而不是启动kswap?

  9. centos – Azure将VM从A2 / 3调整为DS2 v2

    我正在尝试调整前一段时间创建的几个AzureVM,从基本的A3和标准A3到标准的DS2v2.我似乎没有能力调整到这个大小的VM.必须从头开始重建服务器会有点痛苦.如果它有所不同我在VM中运行CentOS,每个都有一个带有应用程序和操作系统的磁盘.任何人都可以告诉我是否可以在不删除磁盘的情况下删除VM,创建新VM然后将磁盘附加到新VM?

  10. centos – 广泛使用RAM时服务器计算速度减慢

    我在非常具体的情况下遇到服务器速度下降的问题.事实是:>1)我使用计算应用WRF>2)我使用双XeonE5-2620v3和128GBRAM(NUMA架构–可能与问题有关!

返回
顶部