Sponsored Content
Top Forums Shell Programming and Scripting Script to find available IP address Post 302969652 by RudiC on Friday 25th of March 2016 07:06:56 AM
Old 03-25-2016
This might help you find all addresses; the evaluation in the END section could be done (among others) like rdrtx1 proposed:
Code:
{ netstat -ntp; ifconfig -a; cat apache2/*; } 2> /dev/null |  awk '
/inet addr/ && !/127/   {sub (/addr:/, _, $2); I[$2]++}
$1 == "tcp"             {sub (/:.*$/,  _, $4); N[$4]++}
/<VirtualHost /         {sub (/:.*$/,  _, $2); A[$2]++}

END                     {
                         for (n in N) print "netstat: ", n, N[n]
                         for (i in I) print "ifconfig:", i, I[i]
                         for (a in A) print "apache2: ", a, A[a]
                        }
'

---------- Post updated at 11:50 ---------- Previous update was at 11:33 ----------

Or, try
Code:
{ netstat -ntp; ifconfig -a; cat apache2/*; } 2> /dev/null |  awk '
/inet addr/ && !/127/   {sub (/addr:/, _, $2); I[$2]++}
$1 == "tcp"             {sub (/:.*$/,  _, $4); N[$4]++}
/<VirtualHost /         {sub (/:.*$/,  _, $2); A[$2]++}

END                     {for (n in N)   {print ((n in I)?((n in A)?"ALL":"N&I"):"NET") ":", n
                                         delete I[n]
                                         delete A[n]
                                        }
                         for (i in I)   {print ((i in A)?"I&A":"IFC") ":", i
                                         delete A[i]
                                        }
                         for (a in A)    print "APA" ":", a


                        }
'

---------- Post updated at 12:06 ---------- Previous update was at 11:50 ----------

Above doesn't recognize IPs in netstat and apache but not in ifconfig. Try instead
Code:
END                     {for (n in N)   {NI = (n in I)
                                         NA = (n in A)
                                         print (NI?(NA?"ALL":"N&I"):(NA?"N&A":"NET")) ":", n


Last edited by RudiC; 03-25-2016 at 07:58 AM..
 

10 More Discussions You Might Find Interesting

1. Programming

Find the IP address that a telnet session uses

Hello Experts, Happy New Year to all of us, In AIX 4.3.3 I am trying to figure out how is possible to find out the IP address that a telnet session - user uses to login in to host machine. My objective is by finding the login IP address to allow the user to login or not. All users uses the... (6 Replies)
Discussion started by: sszago
6 Replies

2. UNIX for Dummies Questions & Answers

How to find i.p address of our server

I don't have root access. How do I find i.p address of our sun server? Thanks. (4 Replies)
Discussion started by: vpotluri
4 Replies

3. UNIX for Advanced & Expert Users

Find LAN Address

Hi, I am wondering how I can find the network address under following situation. Things available: 1. An active network drop without knowing any details about the network. 2. I have windows, Linux, and Solaris machine available to use. Things to achieve: 1. Find out the... (5 Replies)
Discussion started by: jiashi2
5 Replies

4. HP-UX

how to find the IP address of a printer

I'm trying to find the IP address of a print queue. I tried this, but nada. cat /etc/hosts | lp -d lp01 Looked in the hosts file but it's not there (2 Replies)
Discussion started by: abNORMal
2 Replies

5. UNIX for Advanced & Expert Users

Find IP Address of a Printer Q in Hp-Unix

Could anyone help me to identify the IP address of a printer queue with its printer queue name information . (1 Reply)
Discussion started by: lenin1985
1 Replies

6. AIX

How to find the router IP address

How to find the router IP address (2 Replies)
Discussion started by: AIXlearner
2 Replies

7. IP Networking

How to find the IP address of a computer that I am connected to?

Hi all, One of my computers (an iMac) was recently stolen, but I have been able to connect to it over the internet through Apple's 'back to my mac' feature. In order for the police to find these people they need to know the IP address of the stolen computer. I suspect that I will have find the... (6 Replies)
Discussion started by: RJFoulston
6 Replies

8. Red Hat

How to find file which stores IP address

Hi all, I am new to this forum and this is my first question :). Using Red hat Linux.I tried to find file which stores IP address based on different helps given in this forum but did not get success. Here is the system details: -bash-3.2$ lsb_release -a LSB Version: ... (2 Replies)
Discussion started by: Barkha
2 Replies

9. UNIX for Dummies Questions & Answers

How to Find another IP address

Hi Guys, I want to find another(Local host) machine IP address from my machine.. We are all connected in the same server, I mean same LAN. What i done is Connected with that user machine using SSH and SU.. After that i used IFCONFIG but it shows my Ip address. Can not able to get the... (8 Replies)
Discussion started by: Adhi
8 Replies

10. Shell Programming and Scripting

HELP simple script to find e-mail address on a file

Hello guys, im new to to unix/linux i have a text file like this: person1@test.com iisiiasasas person2@test.com 123w2 3233 sajsja person3@test.com jsajjsa sajsjasaj person4@test.com I want to extract only e-mail address and get rid of all other stuff, i want an output like this ... (4 Replies)
Discussion started by: RazorMX
4 Replies
inet_type(4)							   File Formats 						      inet_type(4)

NAME
inet_type - default Internet protocol type SYNOPSIS
/etc/default/inet_type DESCRIPTION
The inet_type file defines the default IP protocol to use. Currently this file is only used by the ifconfig(1M) and netstat(1M) commands. The inet_type file can contain a number of <variable>=<value> lines. Currently, the only variable defined is DEFAULT_IP, which can be assigned a value of IP_VERSION4, IP_VERSION6, or BOTH. The output displayed by the ifconfig and netstat commands can be controlled by the value of DEFAULT_IP set in inet_type file. By default, both commands display the IPv4 and IPv6 information available on the system. The user can choose to suppress display of IPv6 information by setting the value of DEFAULT_IP. The following shows the possible values for DEFAULT_IP and the resulting ifconfig and netstat output that will be displayed: IP_VERSION4 Displays only IPv4 related information. The output displayed is backward compatible with older versions of the ifconfig(1M) and netstat(1M) commands. IP_VERSION6 Displays both IPv4 and IPv6 related information for ifconfig and netstat. BOTH Displays both IPv4 and IPv6 related information for ifconfig and netstat. The command-line options to the ifconfig and netstat commands override the effect of DEFAULT_IP as set in the inet_type file. For example, even if the value of DEFAULT_IP is IP_VERSION4, the command example% ifconfig -a6 will display all IPv6 interfaces. EXAMPLES
Example 1: Suppressing IPv6 Related Output This is what the inet_type file must contain if you want to suppress IPv6 related output: DEFAULT_IP=IP_VERSION4 SEE ALSO
ifconfig(1M), netstat(1M) SunOS 5.10 16 Jun 1999 inet_type(4)
All times are GMT -4. The time now is 06:14 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy