Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

IP Address

by SteveS832001 (Sexton)
on Jul 27, 2005 at 22:14 UTC ( [id://478748]=perlquestion: print w/replies, xml ) Need Help??

SteveS832001 has asked for the wisdom of the Perl Monks concerning the following question:

This is probably asked a lot but I still need help
I need to make a logon script that returns the ip
address of the machine it is running on so that I
can tell it what drives to map by the the ip address


windows <---I hate windows
Most standard machines have one network card, all the
computers that this will run have one

Replies are listed 'Best First'.
Re: IP Address
by esskar (Deacon) on Jul 27, 2005 at 22:41 UTC
Re: IP Address
by sh1tn (Priest) on Jul 27, 2005 at 22:47 UTC
Re: IP Address
by bart (Canon) on Jul 28, 2005 at 00:05 UTC
    If a machine has two network cards, which IP address do you want?

    A machine doesn't have an IP addresss, a network card does.

    Perhaps there are other ways to achieve what you want. I gather this is for Windows... perhaps you could just use an API call to get the name of the machine your script is running on? You can use Win32::API for that, in case there's no more specific (and maybe even better) module available. Don't get me wrong, I love Win32::API.

    #!/usr/local/bin/perl -wl use Win32::API; my $GetComputerName = Win32::API->new("Kernel32", "GetComputerNameA", +"PP", "N") or die "Oops!"; my $computer = pack 'a256', ''; my $size = pack 'V', length($computer)-1; $GetComputerName->Call($computer, $size) or die "Oops, I don't know wh +o I am"; local $\ = "\n"; print unpack 'Z*', $computer;

    But, wat are you actually trying to achieve? Are you trying to map specific volumes to drive letters, or something close? Because there are API calls available for those purposes, too, and you can use them from within Perl.

Re: IP Address
by Old_Gray_Bear (Bishop) on Jul 27, 2005 at 22:41 UTC
    If you are fighting a Windows login-script, use the 'ipconfig' command; if it's one of the *NIX variations, the command is 'ifconfig'. You will have to parse the output in either case to isolate the IP address from the surrounding text.

    ----
    I Go Back to Sleep, Now.

    OGB

Re: IP Address
by ikegami (Patriarch) on Jul 27, 2005 at 22:21 UTC

    I don't know the answer, but I suspect it might be OS-dependant. On which platforms will this run?

    Update:

    After much searching, I found a node on the topic.

    I also came accross the module Win32::IPConfig:

    use Win32::IPConfig (); my $ipconfig = Win32::IPConfig->new(); foreach my $adapter ($ipconfig->get_adapters()) { foreach my $ip_addr ($adapter->get_ipaddresses()) { print("$ip_addr\n"); } }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://478748]
Approved by GrandFather
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-04-25 09:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found