Professional Web Applications Themes

Finding the current IP of my laptop - PERL Beginners

Hello all, I am trying to build a little script (my first one...) that launches several commands depending on the current IP address of my laptop. I would like to use a perl module instead of grep'ing the result of ifconfig. Do you have so guidelines to give me ? Thanks in advance. -- Emmanuel Lesouef...

  1. #1

    Default Finding the current IP of my laptop

    Hello all,

    I am trying to build a little script (my first one...) that launches several
    commands depending on the current IP address of my laptop.

    I would like to use a perl module instead of grep'ing the result of
    ifconfig.

    Do you have so guidelines to give me ?

    Thanks in advance.

    --
    Emmanuel Lesouef
    Emmanuel Guest

  2. #2

    Default RE: Finding the current IP of my laptop

    > I would like to use a perl module instead of grep'ing the result of 

    Getting the IP is pretty platform dependent. If you're on Windows you
    can use Win32::IPHelper, but since you mentioned ifconfig I'm assuming
    you're not. I'd check out search.cpan.org, and failing that, maybe look
    at what's available in your /proc filesystem if your OS has one.
    Luke Guest

  3. #3

    Default RE: Finding the current IP of my laptop

    use IO::Socket;

    $ip = inet_ntoa((gethostbyname($HOSTNAME))[4]);

    Rajesh
     

    Rajesh Guest

  4. #4

    Default RE: Finding the current IP of my laptop

    Sorry. Missed out getting hostname.

    use IO::Socket;
    use Sys::Hostname;

    $HOSTNAME = hostname();
    $ip = inet_ntoa((gethostbyname($HOSTNAME))[4]);

    Rajesh
     
    >[/ref]

    Rajesh Guest

  5. #5

    Default Re: Finding the current IP of my laptop

    On Thu, 22 Apr 2004 14:20:43 -0700
    "Rajesh Dorairajan" <com> wrote:
     

    This is okay provided your laptop has a valid host to IP address
    translation available. On Unix typically either an entry in /etc/hosts
    or a DNS A record entry.

    Take a look at Net::Interface on CPAN. It appears to let you look at
    interface information in a system independent way.

    --
    Smoot Carl-Mitchell
    Systems/Network Architect
    email: com
    cell: +1 602 421 9005
    home: +1 480 922 7313
    Smoot Guest

  6. #6

    Default Re: Finding the current IP of my laptop

    Rajesh Dorairajan wrote: 

    # Either way this only works if /etc/hosts is populated:

    use IO::Socket;
    use Sys::Hostname;

    $HOSTNAME = hostname("postfix.org");
    $ip = inet_ntoa((gethostbyname($HOSTNAME))[4]); print "\n$ip\n";

    # prints 192.168.1.69 regardless...

    __END__

    use IO::Socket;

    "\n$ip\n";
    $ip = Socket::inet_ntoa((gethostbyname(localhost))[4]); print "\n$ip\n";
    $ip = Socket::inet_ntoa((gethostbyname(chasecreek))[4]); print "\n$ip\n";
    $ip = Socket::inet_ntoa((gethostbyname(linksys))[4]); print "\n$ip\n";
    $ip = Socket::inet_ntoa((gethostbyname(loghost))[4]); print "\n$ip\n";
    $ip = Socket::inet_ntoa((gethostbyname(imac))[4]); print "\n$ip\n";

    __END__

    This only prints out what is
    known in /etc/hosts -

    127.0.0.1 localhost
    192.168.1.69 insecurity.org chasecreek loghost
    192.168.1.1 linksys fw
    192.168.1.10 airlan house
    192.168.1.50 imac angela

    Otherwise it gives:
    Usage: Socket::inet_ntoa(ip_address_sv) at IP line x.

    error and exits immediately...

    Cheers :)
    --
    _Sx_ http://youve-reached-the.endoftheinternet.org/ _____
    http://jaxpm.insecurity.org/
    http://cis4dl.insecurity.org/
    Wc Guest

  7. #7

    Default Re: Finding the current IP of my laptop

    <Message original de Smoot Carl-Mitchell en date du jeudi 22 avril 2004 à 17:07>
     [/ref]

    First of all, thank you all for your answers.
     

    And that is exactly the problem :)
    In /etc/hosts :
    127.0.0.1 localhost lothlorien

    Which, is, not the "really" good answer. In fact, I am trying to find a way
    to have the eth0 IP address.
     

    I just had a look at this module. It is promising. Maybe it is the answer.

    For those interested :

    http://search.cpan.org/~srz/Net-Interface-0.04/Interface.pm

    Thank you all.
     

    --
    Emmanuel Lesouef
    Société Taika - fr
    Emmanuel Guest

Similar Threads

  1. Replies: 3
    Last Post: March 9th, 05:19 PM
  2. finding an element in the current doent's parent
    By rob::digitalburn in forum Macromedia Dynamic HTML
    Replies: 2
    Last Post: December 11th, 07:41 PM
  3. Finding the current path
    By Bob Showalter in forum PERL Beginners
    Replies: 0
    Last Post: October 27th, 03:52 PM
  4. Finding current directory?
    By Sugapablo in forum ASP
    Replies: 1
    Last Post: October 3rd, 04:07 PM
  5. Replies: 1
    Last Post: July 20th, 03:27 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139