It’s very easy sorting IP-list. For example you have file ‘ip-list’. To sort IP’s redirect file contents to following sort command. Also collect only unique IP’s in yours list. cat ip-list | sort -n -t . -k 1,1 -k 2,2 -k 3,3 -k 4,4 | uniq >> sorted-ips Didn’t find the answer to your question?…
All posts tagged linux
Python: how to get list of listen sockets in Linux
Here is an example of Python code to get listen socket from Python: def listen_sockets(): listens = [] lines = open(“/proc/net/tcp”).readlines() for l in lines: ls = l.split() if ls[3] == ‘0A’: lp = ls[1].split(‘:’) ip = str(lp[0]) pair = “%s.%s.%s.%s:%s” %( int(ip[6:8], 16), int(ip[4:6], 16), int(ip[2:4], 16), int(ip[0:2], 16), int(lp[1], 16)) listens.append(str(pair)) return listenslistens…
Using ncat to transfer files without SSH
Sometimes you want to transfer some files between two servers but with no SSH installed. There are a lot of ways to do it but the simplest one is to use ncat from nmap package. On receiver you should run: [root@server1 ~]# ncat -v -lp 2223 < ~/fileNcat: Version 5.21 (http://nmap.org/ncat) Ncat: Listening on 0.0.0.0:2223…
How to Install CentOS or Fedora Remotely
The recently posted article describes how to remotely reinstall Debian Linux. In this post I’d like to share a quick and easy way to remotely install CentOS or Fedora. Anaconda installer can considerably simplify the procedure of installing or updating the operating system on a remote server. Here is a quotation from the web page…
Getting idle processes PID from Perl
There is a nice lib for Perl for working with processes in Linux. And it could be used to get PIDs of processes that have been working more than some amount of time. #!/usr/bin/perl -w use strict; use Proc::ProcessTable; my $period = time-(2*60*60); # in this case it’s two hours my $t = new Proc::ProcessTable;…
How to block huge amount of IP addresses with use of ipset in Fedora 14
Sometime you need to block really big numbers of IP addresses. It could be for different reasons. For example, in case of password bruteforce, DDoS attack. Of course, you can block them just in iptables. But there can be a problem. If set of IP addresses contain thousands of items iptables performance decreases (actually, performance…
How to backup and restore your LDAP database
LDAP is Lightweight Directory Access Protocol. It is a way to communicate with directory services. And for many years it has proved its reliability to organize and keep various type of information, for instance, user accounts. It’s useful if you want to provide one credentials for accessing to different resources – servers, web pages, etc.…
Using SNMP extend feature in Nagios
In Supportex we monitor a lot of web services and devices. One of the most convenient ways to monitor various parameters is SNMP extend feature. Let’s consider how it works. Assume you already have SNMP daemon installed. Firstly you need to add configuration line in you SNMP daemon config and restart daemon: extend raid-md0 /usr/local/bin/check_md_raid.pl…
Three ways to make MySQL database dump
Everybody knows – backups are very important. Today a lot of web projects use MySQL to keep data. So you need to know how to set up reliable but simple backup of all your databases. And even if you are only developing you might probably need some tools to make quick dumps and to restore…
How to determine RAID controller type and a model
Almost all modern servers are shipped with RAID controllers – redundant array of independent disks. Despite the fact that this technology was invented more than twenty years ago, nowadays the importance of it can scarcely be exaggerated. In most cases your hosting provider cares about RAID initial setup. So if you don’t want to know…