Sinisterly
IPfinder Bash Script. - Printable Version

+- Sinisterly (https://sinister.li)
+-- Forum: Coding (https://sinister.li/Forum-Coding)
+--- Forum: Coding (https://sinister.li/Forum-Coding--71)
+--- Thread: IPfinder Bash Script. (/Thread-IPfinder-Bash-Script)

Pages: 1 2


RE: IPfinder Bash Script. - L0aD1nG - 08-26-2014

(08-26-2014, 04:24 PM)Singularity Wrote: You know there are more interfaces than just wlan0 / eth0, (for example, ural0 on an OpenBSD os) and these interface names could have been changed / tweaked? That's why I suggested the code I did the first time, as it does not matter what the name of the interface is, it should work on any interface, and regardless of the interface name being used.

Dude executing your code on my terminal prints that :
Quote:127.0.0.1

Also code is written on Linux and should be used on Linux systems, I think in any Linux case should work fine.
I will point it out.

EDIT :

Thats the result for me:
Code:
ninjex@playground:~# echo -ne 'Local IP: '; ifconfig | grep -m1 'inet' | cut -d ':' -f 2 | cut -d ' ' -f 1 Local IP: 127.0.0.1



RE: IPfinder Bash Script. - Singularity_mybb_import13102 - 08-26-2014

I'm pretty sure I'm on a linux machine my friend.
Your 'lo' or loopback interface was probably up top (I didn't think about that), you could just do something like this:

Code:
echo 'Local IP: '; ifconfig | grep 'inet addr:' | awk -F: ' { print $2 } ' | awk ' { print $1 } '

The code you have will not be valid on all *nix machines, that's a fact.

Here will be a prime example:
Code:
vi /etc/udev/rules.d/70-persistent-net.rules
edit this file on your machine and change your interface name of wlan0 to wlan1 (as if you had two wireless interfaces up) and run your code again


RE: IPfinder Bash Script. - L0aD1nG - 08-26-2014

(08-26-2014, 04:26 PM)404# Wrote: Only shows eth0 if you have eth0 and wlan0
What do you mean?
I have wlan0 and eth0 interfaces and it is getting the one that I currently use.

(08-26-2014, 04:26 PM)404# Wrote: also, if you have more than 1 ethernet or wireless adapter, you may not detect the correct one. (eg eth1/wlan1)
yea it depends, but I don't have the ability to test this out, I mean how it should be to work with more adapters, as I have only one.


RE: IPfinder Bash Script. - Singularity_mybb_import13102 - 08-26-2014

We are not saying that this code will not work for you.
We are saying that your code will not work for everyone*

If you just knock off the interface after the ifconfig command, it should work regardless of the interface name as previously pointed out.


RE: IPfinder Bash Script. - The Real Slim Shady - 08-26-2014

(08-26-2014, 04:45 PM)L0aD1nG Wrote: What do you mean?
I have wlan0 and eth0 interfaces and it is getting the one that I currently use.

I mean that if you are using both interfaces at the same time. I commonly have eth0 and wlan0 connected at the same time.

(08-26-2014, 04:45 PM)L0aD1nG Wrote: yea it depends, but I don't have the ability to test this out, I mean how it should be to work with more adapters, as I have only one.

You shouldn't hardcode your interfaces.

And I also have a tun0 at times Tongue


RE: IPfinder Bash Script. - Singularity_mybb_import13102 - 08-26-2014

Let's just drop it and go with this:
Code:
hostname -i | cut -d ' ' -f2



RE: IPfinder Bash Script. - chmod - 08-26-2014

As the rest have said, hardcoding the device names could cause an issue for example on my machine the wireless device is named wlp4s0 so looking wlan0 would be an issue, perhaps take the device name from the user either as input or as an argument which IMO would be the simplest way to solve the issue of device names.


RE: IPfinder Bash Script. - L0aD1nG - 08-29-2014

I think that it will work in the most cases people, either way I had this script for personal use and I decided to share it.
If/when I develop it more I will update it more.
Cheers!