Sponsored Content
Special Forums IP Networking Unix Scripts & Counting TCP Connections Post 302102700 by ghostdog74 on Friday 12th of January 2007 08:07:40 AM
Old 01-12-2007
If you have Python, here's an alternative:

Assuming Sample input is :

Code:
TCP out 64.233.161.99:80 in 192.168.18.52:46778 idle 0:00:00 Bytes 1657961 flags UIO
TCP out 209.104.39.15:80 in 192.168.18.34:52859 idle 0:06:34 Bytes 1026 flags UFRIO
TCP out 64.233.161.104:80 in 192.168.18.19:54409 idle 0:00:02 Bytes 498219 flags UIO
TCP out 209.104.39.15:80 in 192.168.18.22:52154 idle 0:00:01 Bytes 1000 flags UFRIO
TCP out 64.233.161.99:80 in 192.168.18.49:40441 idle 0:00:05 Bytes 60293 flags UIO
TCP out 64.233.161.147:80 in 192.168.18.49:41745 idle 0:00:05 Bytes 1557863 flags UIO


Code:
#!/usr/bin/python
outside = {} #store outside IP address
inside = {} #store inside IP address
for line in open("cisco.log"):
 	line = line.split()
 	out = line[2].split(":")[0] #get out IP address, stripping the port number
 	ins = line[4].split(":")[0] #get inside IP address, stripping the port number
 	if not outside.has_key(out): #if IP address hasn't been seen
 		outside[out] = 1 # initial count to 1
 	else:
 		outside[out] = outside[out] + 1 #add count

 	if not inside.has_key(ins):
 		inside[ins] = 1
 	else:
 		inside[ins] = inside[ins] + 1 #add count

print "Printing count of outside IPs ...." 
for i,k in outside.iteritems():
 	print "IP: %s , count: %d" % (i,k)

print "Printing count of inside IPs...." 	
for i,k in inside.iteritems():
 	print "IP: %s , count: %d" % (i,k)


output:
Code:
Printing count of outside IPs....
IP : 64.233.161.99 , count: 2
IP : 64.233.161.147 , count: 1
IP : 209.104.39.15 , count: 2
IP : 64.233.161.104 , count: 1
Printing count of inside IPs....
IP: 192.168.18.52 , count: 1
IP: 192.168.18.34 , count: 1
IP: 192.168.18.49 , count: 2
IP: 192.168.18.22 , count: 1
IP: 192.168.18.19 , count: 1

 

10 More Discussions You Might Find Interesting

1. Solaris

Scripts - Processes, CPU, Max. Connections

Hi all, Can any one please tell me how to find these in Unix (Commands) 1. Too many processes connected to the server. 2. High Utilization of CPU. 3. Maximum Number of connections with the database. OS: Sun Solaris 5.8 DB : Oracle 10g Thanks and Regards, Prashanth (1 Reply)
Discussion started by: prashanth_gs
1 Replies

2. Programming

C & TCP question: AF_INET vs AF_UNIX

Greetings! I am attempting to write a *basic* network client in C. I have manage to create a socket but I have doubts as far as using AF_INET vs AF_UNIX. At the present time, my client runs with AF_INET. Is AF_UNIX faster across hosts using the same OS flavor (Red Hat)? What is the difference... (1 Reply)
Discussion started by: Alan Christen
1 Replies

3. Shell Programming and Scripting

A bi directional script that will monitor the TCP/IP connections between two physical

Dear All , I'm looking for a unix script that will monitor the TCP/IP connections between two physical ip addresses and when it dectes an IP is down it generates an alarm and sends SMS to mobile numbers. Can any one help, I need this urgently. Waiting for positive replies.. ... (3 Replies)
Discussion started by: samura
3 Replies

4. Red Hat

How to kill all active tcp connections from an IP?

How to kill all active tcp connections from an IP? I am using CentOS (3 Replies)
Discussion started by: an00p
3 Replies

5. UNIX for Dummies Questions & Answers

syntax for counting & printing record count

Hi I have a complex script which outputs a text file for loading into a db. I now need to enhance this script do that I can issue an ‘lp' command to show the count of the number of records in this file. Can anybody give me the necessary syntax ? (2 Replies)
Discussion started by: malts18
2 Replies

6. IP Networking

How to test max number of tcp connections

Hello, I wanna test max tcp connection value. Please suggest how to do that. Thanks. (2 Replies)
Discussion started by: gstoychev
2 Replies

7. Shell Programming and Scripting

Help with awk array syntax & counting script

..... (3 Replies)
Discussion started by: elbee11
3 Replies

8. Shell Programming and Scripting

[Solved] Isolating & Counting IP from log file

Dear Community, today my website was under attack for several hours. 2 specific IPs make a tons of "get requests" to a specific page and apache server goes up and down. Now the problem is solved because I put in firewall blacklist these IPs, but I took a lot of time to analyze the apache log to... (6 Replies)
Discussion started by: Lord Spectre
6 Replies

9. IP Networking

Need to know reason for connections closed in netstat -p tcp

Hello netstat -p give below 6634176 connections as closed.How do we trace that which all connections are being closed on the server? 1366888371 data packet headers correctly predicted 1195906 connection requests 5227320 connection accepts 5992919... (6 Replies)
Discussion started by: Vishal_dba
6 Replies

10. UNIX for Advanced & Expert Users

30 tcp connections Established for a while and after a few minutes are close

Good morning, I need your help please After Restarting Aps or connection, these are connections tcp 0 0 10.80.1.26.57597 10.81.248.79.53008 ESTABLISHED tcp 0 47 10.80.1.26.57607 10.81.248.79.53008 ESTABLISHED tcp 0 0 ... (4 Replies)
Discussion started by: alexcol
4 Replies
tgt-setup-lun(8)					      System Manager's Manual						  tgt-setup-lun(8)

NAME
tgt-setup-lun - creates a target, adds a device to the target and defines initiators that can connect to the target SYNOPSIS
tgt-setup-lun -d device -n target_name [initiator_IP1 initiator_IP2 ...] [-h] DESCRIPTION
Starts tgtd if necessary and creates a target according to the supplied target_name. The format of the target name is as follows: iqn.2001-04.com.<hostname>-<target_name> The target name must be unique. The script then adds the requested device to the target. If specific IP addresses are defined, it adds them to the list of allowed initia- tors for that target. If no IP addresses is defined, it defines that the target accepts any initiator. EXAMPLES
Create a target that uses /dev/sdb1 and allows connections only from 192.168.10.81: tgt-setup-lun -d /dev/sdb1 -n my_target 192.168.10.81 Create a target that uses /dev/sdb1 and allows connections only from 192.168.10.81 and 192.168.10.82: tgt-setup-lun -d /dev/sdb1 -n my_target 192.168.10.81 192.168.10.82 Create a target that uses /dev/sdb1 and allows connections from any initiator: tgt-setup-lun -d /dev/sdb1 -n my_target Display help: tgt-setup-lun -h AUTHOR
Written by Erez Zilber REPORTING BUGS
Report bugs to <erezz@voltaire.com>. COPYRIGHT
Copyright (C) Voltaire Ltd. 2008. tgt-setup-lun(8)
All times are GMT -4. The time now is 10:28 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy