New topic: 

How to retrieve the default gateway IP and its dns name?

<http://forums.realsoftware.com/viewtopic.php?t=22861>

       Page 1 of 1
   [ 5 posts ]                 Previous topic | Next topic         Author  
Message       fishmonger           Post subject: How to retrieve the default 
gateway IP and its dns name?Posted: Wed Jun 11, 2008 4:54 pm                    
    
Joined: Sat May 17, 2008 9:14 pm
Posts: 38              This is my first RB app (beyond a few tutorials) and I 
have a 2 fold question.

1)  I see that System.GetNetworkInterface(0) can get the IP, mask, and mac but 
not the default gateway.  Is there a built-in function elsewhere that returns 
the gateway IP?  If not, what is the best method for retrieving the gateway IP?

This is what I've come up with, but it seams a little verbose compared to how 
I'd do it in Perl.
Code:dim dns as String
dim gateway as String
dim ipconfig as String
dim cmd as shell

cmd = new shell
cmd.execute "ipconfig"
ipconfig = cmd.result

Dim RegEx As RegEx
Dim Match As RegExMatch
RegEx = New RegEx
RegEx.Options.TreatTargetAsOneLine = true
RegEx.SearchPattern = "Default Gateway.+ ((\d+\.){3}\d+)"

Match = RegEx.Search(ipconfig)

if Match <> Nil and cmd.errorCode = 0 then
  gateway = Match.SubExpressionString(1)
  MsgBox "<" + gateway + ">"  // see if regex returned the gateway IP and 
nothing else
  
  // retrieve the dns name for the gateway IP, then parse it to retrive the 
store number
  dns = System.Network.LookupDNSAddress( gateway )
  
  MsgBox dns  // dns lookup failed...returned passed in IP address
else
  msgBox "Error: " + str(cmd.errorCode) + "\n" + gateway
end if


2)  System.Network.LookupDNSAddress (on Windows platform) returns the passed-in 
IP address instead of the dns name.  Has RB come up with a patch to fix this 
issue?  I could parse the output of nslookup like I did with ipconfig, but I 
was hoping for a more eloquent solution.

RB Version: 2008 r2   
                            Top                timhare           Post subject: 
Re: How to retrieve the default gateway IP and its dns name?Posted: Wed Jun 11, 
2008 5:19 pm                        
Joined: Fri Jan 06, 2006 3:21 pm
Posts: 3127
Location: Portland, OR  USA              The LR has this:
Quote:The LookupDNSAddress and LookupIPAddress methods return empty strings on 
errors but return the string that was passed to the function if the address 
could not be resolved.

If I pass it an address that is resolvable, I do get the name back.  (Windows 
XP, RB2008r2)  

Note that my router (my default gateway) does not have a dns name, so I get the 
IP address back for it.

Tim   
                            Top               fishmonger           Post 
subject: Re: How to retrieve the default gateway IP and its dns name?Posted: 
Wed Jun 11, 2008 5:32 pm                        
Joined: Sat May 17, 2008 9:14 pm
Posts: 38              timhare wrote:The LR has this:
Quote:The LookupDNSAddress and LookupIPAddress methods return empty strings on 
errors but return the string that was passed to the function if the address 
could not be resolved.

If I pass it an address that is resolvable, I do get the name back.  (Windows 
XP, RB2008r2)  

Note that my router (my default gateway) does not have a dns name, so I get the 
IP address back for it.

Tim
The IP that I'm resolving is 10.100.0.1

>From the cmd window both of the following commands will resolve the IP's dns 
>name.

ping -a 10.100.0.1
nslookup 10.100.0.1

So, why can't RB handle the resolution?   
                            Top                Nux           Post subject: Re: 
How to retrieve the default gateway IP and its dns name?Posted: Thu Jul 31, 
2008 11:41 pm                        
Joined: Sat May 26, 2007 11:37 pm
Posts: 5              I don't know why RB isn't resolving the DNS/IP,..  
however for the gateway command, it looks like your executing Shell commands, 
to get the IP address and Parsing the information.  if this is on a windows 
machine,  you could try to shell a command like Route Print, and parse the 
gateway address, along with any other route information that you may want.   
                            Top               fishmonger           Post 
subject: Re: How to retrieve the default gateway IP and its dns name?Posted: 
Fri Aug 01, 2008 4:26 pm                        
Joined: Sat May 17, 2008 9:14 pm
Posts: 38              Nux,

Thanks for the suggestion, but this project doesn't need any of the routing 
info and parsing the output of ipconfig will be more efficient than parsing 
'route print'.

What I can't understand is why RS can't figure out how fix the bug in in their 
LookupDNSAddress() function.  In another related thread Aaron Ballman said that 
the issue is due to a Windows winsock limitation in W2K and below.  I have a 
hard time believing that for several reasons, a) Other threads show that XP and 
OS X 10.4.9 is having the same problem, b)  MonkeybreadSoftware says that they 
have an RB plugin that works, c) other languages, such as Perl, are able to 
properly handle dns lookups on Windows.   
                            Top            Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 5 posts ]     

-- 
Over 900 classes with 18000 functions in one REALbasic plug-in. 
The Monkeybread Software Realbasic Plugin v8.1. 

&lt;http://www.monkeybreadsoftware.de/realbasic/plugins.shtml&gt;

[email protected]

Reply via email to