Lan & Global IP


 
Thread Tools Search this Thread
Special Forums IP Networking Lan & Global IP
# 1  
Old 04-04-2015
Signal Lan & Global IP

Heyas

Wasnt sure where to post, but thought this is most matching.
Thanks to Neo we can now see our IP and much more on: What is My IP Address?

I've always wanted a script to get my IP's, and thanks to Neo's effort, i now could do.
Outputs as follows:
Code:
$ myip.sh 
Internal	192.168.10.15
External	215.163.234.18

Code:
#!/usr/bin/env bash
# File: 	myip.sh
# Description:	Simply prints internal and external IP using https://www.unix.com/what-is-my-ip.php
# ------------------------------------------------------
#
#	Variables
#
	URL=https://www.unix.com/what-is-my-ip.php
	DATA=$(curl -s $URL) > /dev/zero
	str="DNS Lookup For"
#
#	Action & Display
#
	printf "%s\t%s\n" "Internal" "$(ifconfig | grep -i broadcast | grep ^[[:space:]] | awk '{ print $2}')"
	printf "%s\t%s\n" "External" "$(echo "$DATA" | sed s,"$str","\n\n$str",g  | sed s,"<"," ",g|grep "$str" | awk '{print $4}')"

Hope you like Smilie
Happy easter!

Last edited by sea; 04-04-2015 at 10:36 AM.. Reason: URL fix
This User Gave Thanks to sea For This Post:
# 2  
Old 04-04-2015
This will work for some common configurations, but it's possible for an adaptor to have more than one IP address.
# 3  
Old 04-04-2015
Nice! Some opportunities to simplify:
Code:
lynx -dump https://www.unix.com/what-is-my-ip.php | awk '/DNS Lookup For/ {print "External: ", $NF}'
External:  215.163.234.18
ifconfig | awk -F"[ :]*" '/inet addr/ {print "Internal: ", $4}'
Internal:  10.1.1.1
Internal:  127.0.0.1

This User Gave Thanks to RudiC For This Post:
# 4  
Old 04-04-2015
Had to change your awk a bit for my system:
Code:
#
#	Variables
#
	URL=https://www.unix.com/what-is-my-ip.php
	T="T=\\t"
#
#	Action & Display
#
	lynx -dump "$URL" | awk '/DNS Lookup For/ {print "External: "T, $NF}' $T
	ifconfig | awk -F" " '/netmask / {print "Internal:"T, $2}' $T


Last edited by sea; 04-04-2015 at 05:46 PM.. Reason: changed code
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Question about global environment variables & fork() exec()

Hello... And thanks in advance for any help anyone can offer me on my question! I've been doing a lot of reading to try and find my answer... But I haven't had any luck What I'm trying to understand is where a child process inherits global environment variables from? I understand the exec()... (2 Replies)
Discussion started by: bodisha
2 Replies

2. Solaris

Date and time change in global and non global zone

Hi, If I change date and time in global zone, then it will affect in non global zones. During this process what files will get affect in non global zones and which mechanism it's using to change. gloabl zone:Solaris 11.3 X86 TIA (1 Reply)
Discussion started by: Sumanthsv
1 Replies

3. Solaris

Global and non-global zone resource sharing - tricky

hi all, Just a simple question but i cant get the answers in the book - In my globalzone , assuming i have 4 cpus (psrinfo -pv = 0-3), if i set dedicated-cpu (ncpus=2) for my local zone Is my globalzone left with 2 cpus or still 4 cpus ? Does localzone "resource reservation.e.g. cpu in... (6 Replies)
Discussion started by: javanoob
6 Replies

4. IP Networking

Local Lan, no-ip directed DNS forward, surf within lan

Hi, We have a website running on a local centos 5.4 surfer, static IP. The domain.com uses no-ip.com to take care of the DNS, it forwards all to my server. My router receives the port 80 call, routes it to my server and the world can see domain.com perfectly fine. However, we cannot see... (3 Replies)
Discussion started by: lawstudent
3 Replies

5. Solaris

How to identify a global or non-global Solaris server?

Hi, I have Solaris zone configured with Solaris 9 and 10. In Solaris 10(non global), I use the command “zonename” to get whether it is global or non-global server. For Solaris 9, what command I can use to get whether it is global or non-global server. Regards, Kalai :confused: (25 Replies)
Discussion started by: kalpeer
25 Replies

6. Solaris

How to see global hostname by logging in non global zones?

Hi guru Could any one help me by letting me know, how to see global hostname by logging in non global zones Regards (2 Replies)
Discussion started by: girish.batra
2 Replies

7. Solaris

How to access ENV variables of non global zones in global zone???

Hi Guys, My requirement is I have file called /opt/orahome/.profile in non global zone. PATH=/usr/bin:/usr/ucb:/etc:/usr/sbin:/usr/local/bin:/usr/openwin/bin:. export PATH PS1="\${ORACLE_SID}:`hostname`:\$PWD$ " export PS1 EDITOR=vi export EDITOR ENV=/opt/orahome/.kshrc export ENV... (1 Reply)
Discussion started by: vijaysachin
1 Replies

8. Solaris

Is there two different kernel`s running in global and non global zone?

Hi All, I want to know for non global zone there will be different kernal running? (1 Reply)
Discussion started by: vijaysachin
1 Replies

9. Solaris

How can we copy a directory from Global to Non-global zone?

Hi All, How can we copy a directory from global zone to non-global zone using SCP command? (8 Replies)
Discussion started by: vijaysachin
8 Replies

10. Solaris

How to configure private LAN and coporate LAN on the same machine-Solaris10

Hi , I am trying to configure a private LAN and corporate LAN on the same machien on Solaris 10. How can I achieve this? Thanks (1 Reply)
Discussion started by: deedee
1 Replies
Login or Register to Ask a Question