Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Dave Roth wrote something that does this.

Here you go.

# GetIP.pl # -------- # This will retrieve all IP Addresses that are bound # to network devices on a specified machine. This includes IPs that +are # bound to any NIC (network card, RAS dail up, etc). # If a particular NIC specifies 0.0.0.0 (typically to indicate that +the # NIC will request an IP via DHCP, PPP, etc) it will be ignored. # ALL IPs are discovered even on cards that are disabled. # # Syntax: # perl GetIP.pl [Machine Name] # # Examples: # perl GetIP.pl # perl GetIP.pl \\server # # 1999.03.09 roth # # Permission is granted to redistribute and modify this code as long + as # the below copyright is included. # # Copyright 1999 by Dave Roth # Courtesty of Roth Consulting # http://www.roth.net/ use Win32::Registry; %KeyName = ( serviceroot => 'System\CurrentControlSet\Services', tcplink => 'Tcpip\Linkage', tcplink_disabled => 'Tcpip\Linkage\Disabled', tcpparam => 'Tcpip\Parameters', deviceparam_tcp => 'Parameters\Tcpip', ); $Root = $HKEY_LOCAL_MACHINE; if( $Machine = $ARGV[0] ) { $HKEY_LOCAL_MACHINE->Connect( $Machine, $Root ) || die "Could not +connect to the registry on '$Machine'\n"; } if( $Root->Open( $KeyName{serviceroot}, $ServiceRoot ) ) { # Get the device names of the cards tcp is bound to... if( $ServiceRoot->Open( $KeyName{tcplink}, $Links ) ) { my( $Data ); if( $Links->QueryValueEx( "Bind", $DataType, $Data ) ) { $Data =~ s/\n/ /gs; $Data =~ s/\\Device\\//gis; $Data =~ s/^\s+(.*)\s+$/$1/gs; push( @Devices, ( split( /\c@/, $Data ) ) ); } $Links->Close(); } # Get the device names of cards that tcp is bound to but disabled. +.. if( $ServiceRoot->Open( $KeyName{tcplink_disabled}, $Links ) ) { my( $Data ); if( $Links->QueryValueEx( "Bind", $DataType, $Data ) ) { $Data =~ s/\s+//gs; $Data =~ s/\\Device\\//gis; push( @Devices, ( split( /\c@/, $Data ) ) ); } $Links->Close(); } foreach $DeviceName ( @Devices ) { my( $DeviceTCPKey ); if( $ServiceRoot->Open( "$DeviceName\\$KeyName{deviceparam_tcp +}", $DeviceTCPKey ) ) { my( @CardIPs, @CardSubNets ); my( $Data, $iCount, $IPAddress ); # Get the IP addresses... if( $DeviceTCPKey->QueryValueEx( "IPAddress", $DataType, $ +Data ) ) { $Data =~ s/\s+//gm; push( @CardIPs, ( split( /\c@/, $Data ) ) ); } # Get the Subnet masks... if( $DeviceTCPKey->QueryValueEx( "SubnetMask", $DataType, +$Data ) ) { $Data =~ s/\s+//gm; push( @CardSubNets, ( split( /\c@/, $Data ) ) ); } # Push our new found data onto the stack... $iCount = 0; map { my( %Hash ); # We don't want 0.0.0.0 since it means the IP will be +procured via DHCP or something... next if( $_ eq '0.0.0.0' ); $Hash{ip} = $_; $Hash{subnet} = $CardSubNets[$iCount]; push( @IP, \%Hash ); $iCount++; } ( @CardIPs ); $DeviceTCPKey->Close(); } } print "This machine $Machine has the following IP addresses:\n"; foreach $IPStruct ( @IP ) { print "\t$IPStruct->{ip} \t(subnet: $IPStruct->{subnet})\n"; } $ServiceRoot->Close(); }

In reply to Re: List all network interfaces on the local machine? by Marza
in thread List all network interfaces on the local machine? by mobiGeek

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Domain Nodelet?
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this?Last hourOther CB clients
    Other Users?
    Others cooling their heels in the Monastery: (4)
    As of 2024-07-13 02:23 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found

      Notices?
      erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.