New topic in Networking: How to retrieve the default gateway IP and its dns name?
fishmonger - Wed Jun 11, 2008 4:54 pm <http://forums.realsoftware.com/viewtopic.php?t=22861> 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
-- Over 900 classes with 18000 functions in one REALbasic plug-in. The Monkeybread Software Realbasic Plugin v8.1. <http://www.monkeybreadsoftware.de/realbasic/plugins.shtml> [email protected]
