-2

I am trying to get this function to file .bashrc

This is my function :

function my_ip() {
    echo "internal or external?"
    read -r choise
    if [ "$choise" == "internal" ] ;then
        echo "please enter the name of the card that youare using at";
        read -r card ;
        ifconfig "$card" | grep 'inet addr' |cut -d':' -f2|cut -d ' ' -f1;
    else
        wget -qO- http://noc.co.il |grep "var VisitorCountry" | awk     '{print$4}'|cut -d '"' -f4;  
    fi
}

My goal is that the function will quickly give me my IP by choosing internal or external

if I want to automatically displays the network card ("without the need to ask Which network card do you use(The computer automatically detects which network card the user uses and will put the name as a variable at the right commend for internal IP , how can I get him to identify what card the user use(WLAN0 WLAN1 etc.) ?

H_meir
  • 333
  • 4
  • 13
  • 4
    Pasting it into http://www.shellcheck.net/ reveals several errors. Go through them and update your question if the problem persists. – fedorqui Jul 29 '15 at 07:31
  • 1
    `if ["$choise" == "internal";then` ?? – Avinash Raj Jul 29 '15 at 07:32
  • `choice`. `fi`. http://stackoverflow.com/help/mcve – Karoly Horvath Jul 29 '15 at 07:49
  • You *do* know that there is no need to terminate each bash line with `;`? – DevSolar Jul 29 '15 at 07:51
  • @fedorqui Thanks for the link! – legends2k Jul 29 '15 at 07:51
  • Now title and question don't match at all... – DevSolar Jul 29 '15 at 07:54
  • thank you fedorqui for the link ,thanks avinash and karoly i fixed this ,Dev i didnt knew this , i thot this is the proper way to right it , thank you – H_meir Jul 29 '15 at 07:54
  • can anyone help me with the otter queshtion? – H_meir Jul 29 '15 at 07:55
  • "Which network card the user uses" --- there is no such thing in many cases. A system might be connected to *multiple* networks using *different* interfaces. (Firewall systems are not the only example here.) If you have only *one* network interface, the answer is trivial. If you have *multiple* interfaces, you have to be more specific about what constitutes the user "using" a specific one. *For what*? – DevSolar Jul 29 '15 at 07:57
  • i want to find which network card generate the internal ip from all the card installed on the computer (ath0 / wlan0/ath1/lan1 etc.) – H_meir Jul 29 '15 at 08:03
  • "which network card generate the internal ip" -- what is "the internal ip" in your eyes? Check [this question](http://stackoverflow.com/questions/5548032), and note that the accepted answer is using a deprecated option to `hostname`. The *second* answer is the good one. – DevSolar Jul 29 '15 at 08:05
  • when i use ifconfig i can see what is my internal ip (normaly if you use wifi its will be under wlan0 )represent by "inet address" – H_meir Jul 29 '15 at 08:10
  • @H_meir: Yes, if you're lucky and have only that one interface. The system I am currently sitting at has three (wlan0, eth0, eth1)... – DevSolar Jul 29 '15 at 08:18

1 Answers1

0

A system can have more than one IP address. Which one of them is the one you are looking for? You did not specify that.

There are multiple questions related to finding IP addresses with bash:

If none of those float your boat, consider closing this question and posting a new one with more precise phrasing what you are looking for.

Community
  • 1
  • 1
DevSolar
  • 67,862
  • 21
  • 134
  • 209