get same info as ipconfig?

T

Todd Gardner

Hello Everyone,

Is there a cross platform command to get the same info that ipconfig
[w2k] or ifconfig[POSIX] returns directly in Ruby?

Thanks,

Todd
 
M

Mikael Brockman

Hello Everyone,

Is there a cross platform command to get the same info that ipconfig
[w2k] or ifconfig[POSIX] returns directly in Ruby?

Thanks,

Todd

Nope, not really, I don't think. If you want to figure out the address
of the interface closest to the Internet, as far as I know the most
portable way is to open a socket to a machine elsewhere on the Internet
and look at which source address the operating system chose.

mikael
 
D

Daniel Berger

Hello Everyone,

Is there a cross platform command to get the same info that ipconfig
[w2k] or ifconfig[POSIX] returns directly in Ruby?

Thanks,

Todd

I see Sam mentioned sys-host (one of my packages), but it's not very
useful at the moment. However, I plan to rewrite the Windows portion
to use OLE + WMI. You can get the info you need on Windows like this:

require "win32ole"

ole = WIN32OLE.connect("winmgmts://")

# Avoid non-working adapters by setting 'IPEnabled' to true
query = "select * from Win32_NetworkAdapterConfiguration where
IPEnabled = True"

ole.ExecQuery(query).each{ |nic|
p nic.IpAddress
p nic.IpSubnet
p nic.DefaultIPGateway
}

Regards,

Dan
 
T

Todd Gardner

Hello Everyone,

Is there a cross platform command to get the same info that ipconfig
[w2k] or ifconfig[POSIX] returns directly in Ruby?

Thanks,

Todd

I see Sam mentioned sys-host (one of my packages), but it's not very
useful at the moment. However, I plan to rewrite the Windows portion
to use OLE + WMI. You can get the info you need on Windows like this:

require "win32ole"

ole = WIN32OLE.connect("winmgmts://")

# Avoid non-working adapters by setting 'IPEnabled' to true
query = "select * from Win32_NetworkAdapterConfiguration where
IPEnabled = True"

ole.ExecQuery(query).each{ |nic|
p nic.IpAddress
p nic.IpSubnet
p nic.DefaultIPGateway
}

Regards,

Dan

Hell Dan,

When I run the above code on w2k I get this.

=============================
["192.168.1.115"]
["255.255.255.0"]
["192.168.1.1"]

And then a modal dialog pops up and takes focus.

[dialog]
Run time error!
Program: C:\ruby\bin\\rubyw.exe
This application requested the run time to terminate in an unusual
way. Please contact the application support team for more
information."
============================

Might you have any idea how I can determine what my WAN IP address is?
It is not in ipconfig. My Linksys router does show it to me at...

http://192.168.1.1/Status.htm
LAN:
(MAC Address: 00-04-5A-EF-5C-9F)
IP Address: 192.168.1.1
Subnet Mask: 255.255.255.0
DHCP server: Enabled
WAN:
(MAC Address: 00-04-5A-EF-5C-A0)
IP Address: 68.164.157.203
DNS: 207.69.188.186
207.69.188.185
0.0.0.

I have DSl and the IP address earthlink DSL gives me changes quite
frequently. Every few days.

Thanks,

Todd
 
D

Daniel Berger

Hello Everyone,

Is there a cross platform command to get the same info that ipconfig
[w2k] or ifconfig[POSIX] returns directly in Ruby?

Thanks,

Todd

I see Sam mentioned sys-host (one of my packages), but it's not very
useful at the moment. However, I plan to rewrite the Windows portion
to use OLE + WMI. You can get the info you need on Windows like this:

require "win32ole"

ole = WIN32OLE.connect("winmgmts://")

# Avoid non-working adapters by setting 'IPEnabled' to true
query = "select * from Win32_NetworkAdapterConfiguration where
IPEnabled = True"

ole.ExecQuery(query).each{ |nic|
p nic.IpAddress
p nic.IpSubnet
p nic.DefaultIPGateway
}

Regards,

Dan

Hell Dan,

When I run the above code on w2k I get this.

=============================
["192.168.1.115"]
["255.255.255.0"]
["192.168.1.1"]

And then a modal dialog pops up and takes focus.

[dialog]
Run time error!
Program: C:\ruby\bin\\rubyw.exe
This application requested the run time to terminate in an unusual
way. Please contact the application support team for more
information."
============================

Hi Todd,

Hm...I suspect you need to update your version of win32ole. The
version that comes with 1.8.1 is 0.5.4, but the latest is 0.5.5 (and
will be part of 1.8.2).
Might you have any idea how I can determine what my WAN IP address is?
It is not in ipconfig. My Linksys router does show it to me at...

Take a look at the attributes available for the
Win32_NetworkAdapterConfiguration class at
http://msdn.microsoft.com/library/d...sdk/wmi/win32_networkadapterconfiguration.asp

If none of those fields fit your needs, you'll have to dig around and
see what you can find. Off the top of my head I'm not sure.

BTW, I should have a new release of sys-host out this week.

Regards,

Dan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top