# Determining Host Default Route Based Upon IP Address

**URL:** <https://www.ruby-forum.com/t/determining-host-default-route-based-upon-ip-address/133578>\
**Category:** Ruby\
**Created:** [April 1, 2008, 9:05pm UTC](https://www.ruby-forum.com/t/determining-host-default-route-based-upon-ip-address/133578 "2008-04-01T21:05:42Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brian\_Mac](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/a88e4f/32.png) [@Brian\_Mac](https://www.ruby-forum.com/u/Brian_Mac)\
**Post date:** [April 1, 2008, 9:05pm UTC](https://www.ruby-forum.com/t/determining-host-default-route-based-upon-ip-address/133578/1 "2008-04-01T21:05:42Z")

</div>

hi all,

i’m in the early stages of developing a cross-platform utility to  
allow end users of an in-house application to diagnose ‘application’  
issues. one aspect i’m trying to account for is network problems and  
this is where i’m running into some issues…

i know how to find ip address information and display routing tables  
on windows and various flavors of unix. i can display the ip address  
easily enough using pure ruby but i’m really struggling finding a  
super clean way to determine the default route based upon current ip  
address. basically i’m thinking of:

1. getting host’s ip address
2. getting subnet mask
3. creating array of all default routes
4. iterating thru array of default routes to find default route for  
current ip and returning that value

i would love to hear if i’m taking the way-wrong road to get to where  
i want to go. any help is greatly appreciated.

thanks!  
brian
