perl + how to get ip address of local machine
I have machine which has three newtork card all assigned with 2 Ip address in the following manner :-
Local Area Connection 1 DHCP Enabled. . . . . . . . . . . : No IP Address. . . . . . . . . . . . : 192.168.251.145 Subnet Mask . . . . . . . . . . . : 255.255.255.0 IP Address. . . . . . . . . . . . : 192.168.251.134 Subnet Mask . . . . . . . . . . . : 255.255.255.0 Default Gateway . . . . . . . . . : 192.168.251.99 DNS Servers . . . . . . . . . . . : 192.168.251.101 Local Area Connection 2 IP Address. . . . . . . . . . . . : 192.168.251.146 Subnet Mask . . . . . . . . . . . : 255.255.255.0 IP Address. . . . . . . . . . . . : 192.168.251.137 Subnet Mask . . . . . . . . . . . : 255.255.255.0 Local Area Connection 3 IP Address. . . . . . . . . . . . : 192.168.251.148 Subnet Mask . . . . . . . . . . . : 255.255.255.0 IP Address. . . . . . . . . . . . : 192.168.251.139 Subnet Mask . . . . . . . . . . . : 255.255.255.0 Now the problem is how to get the ip address(both the primary and secdonry address) based on the connection name. for example if want to get all ip address assigned on local area connection 1 (both primary and secondary Seperately). Are there any inbuilt functions in perl to get all ip address based on the network connection name. Or is there any way to get it from the registry , Iam not sure whether it is stored in registry? |
guess your in windows, its a bit messy but very easy
my @data = `ipconfig`; then read though the array for your connection name and ip addresses |
Quote:
I'd like to add a comment on 'inbuilt functions' in Perl. Perl is as much CPAN as you can throw at it. For instance if you use the module Net::Address::Ethernet you'll get inbuilt functionality but then there are some dependencies on other modules such as: Env::Path Regexp::Common Test::Pod In the end, just parse the buffer and that's quite good. But I thought I'd take this opportunity to mention that there are 'hundreds' of modules available for Perl from the CPAN (cpan.org) and those adds a whole lot of 'inbuilt' functionalities. Cheers. |
it would probably be pretty easy if you'd do something like this
use system function or exec function equivalent from c/c++ to perl exec("ifconfig > stuff.txt"); then you parse stuff.txt to get what you need with the filestream functions in perl. that would be all i think |
Quote:
Code:
open FILEHANDLE, 'ipconfig |' or die 'blah'; |
Quote:
my @buffer = `ipconfig`; Then you parse the buffer. You could even derive a hash from this if you need the info often. Keep the complicated stuff only when it's needed. When it can be simple, keep it simple. And right. |
All times are GMT -5. The time now is 11:22 PM. |