Bash: sort IP addresses

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?…

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…

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…