Mirage Source http://web.miragesource.net/forums/ |
|
[Feature] Getting your actual IP *edited* http://web.miragesource.net/forums/viewtopic.php?f=183&t=5535 |
Page 1 of 76 |
Author: | GIAKEN [ Fri Apr 24, 2009 1:33 am ] |
Post subject: | [Feature] Getting your actual IP *edited* |
So, I just wrote up my own fine ass function for getting your actual IP. At first it was just 1 line of code, and I'm sure you've seen code using INet before to get your actual IP...but none like this, good sir! First, open your server: In modGlobals, add this: Code: Public ACTUAL_IP As String Public IP_Source As String Then in Sub UpdateCaption, replace the: Code: frmServer.Socket(0).LocalIP With: Code: ACTUAL_IP Then in InitServer (before the final SetStatus message) add this: Code: IP_Source = "org" ACTUAL_IP = GetActualServerIP What I did with the IP_Source is basically let you choose between using whatismyip.com or whatismyip.org (sometimes one's down). Either make IP_Source = "com" or "org". In my engine I have this load from an INI file...but doing an INI file is a totally different tutorial. Then go to Project > Components. Look for Microsoft Internet Transfer Control 6.0 and check it and click OK. Now open frmServer and add the INet control anywhere you want and make sure it's named: INet. Then click on your new INet control and in the properties box make sure Index is set to 0 (it's blank by default). And...here's the magic itself. Add this to modGeneral (or any other module is fine): Code: '''''''''''''''''''''''''''''''''''''''''''' ' Function written from scratch by: GIAKEN ' '''''''''''''''''''''''''''''''''''''''''''' Public Function GetActualServerIP() As String Dim RetryValue As Long Load frmServer.INet(1) Retry: 'after 2 seconds time the request out frmServer.INet(RetryValue).RequestTimeout = 2 Select Case IP_Source Case "org" Call SetStatus("Retrieving actual IP from whatismyip.org...") On Error Resume Next GetActualServerIP = frmServer.INet(RetryValue).OpenURL("http://whatismyip.org", icString) On Error GoTo ErrHandler Case "com" Call SetStatus("Retrieving actual IP from whatismyip.com...") On Error Resume Next GetActualServerIP = frmServer.INet(RetryValue).OpenURL("http://whatismyip.com/automation/n09230945.asp", icString) On Error GoTo ErrHandler End Select 'if the IP is blank, then handle it as an error If LenB(GetActualServerIP) = 0 Then GoTo ErrHandler Call SetStatus("Successfully retrieved actual IP.") Exit Function ErrHandler: 'clear the RTE error just in case so we can properly continue Err.Clear Call SetStatus("Failed to retrieve actual IP address: timed out.") frmServer.INet(RetryValue).Cancel RetryValue = RetryValue + 1 If RetryValue <= 1 Then ' since we failed, we'll retry with another method If IP_Source = "org" Then IP_Source = "com" Else IP_Source = "org" End If GoTo Retry End If 'couldn't get the actual IP, so just use the local one... GetActualServerIP = frmServer.Socket(0).LocalIP End Function The reason I had to make the INet an array was because when INet times out it requests a time out when you try again instantly...so I just made Inet 0 and 1 so if 0 fails 1 can attempt to back it up. |
Author: | Nean [ Fri Apr 24, 2009 1:47 am ] |
Post subject: | Re: Getting your actual IP |
Really buggy, I don't recommend using this way. Too slow... Just kidding GIAKEN, it looks good. |
Author: | GIAKEN [ Fri Apr 24, 2009 10:52 pm ] |
Post subject: | Re: Getting your actual IP |
Anybody having any problems? |
Author: | Jared [ Fri Apr 24, 2009 11:07 pm ] |
Post subject: | Re: Getting your actual IP |
GIAKEN wrote: Anybody having any problems? Worked fine for me, Thank you. |
Author: | GIAKEN [ Sat Apr 25, 2009 11:28 am ] |
Post subject: | Re: Getting your actual IP |
You're welcome |
Author: | GIAKEN [ Mon May 11, 2009 3:40 am ] |
Post subject: | Re: [Feature] Getting your actual IP *edited* |
Just worked on the GetActualServerIP function, redoing the error handling. (it was bugging if it timed out twice) |
Author: | wanai [ Tue Jan 04, 2022 11:23 am ] |
Post subject: | Re: [Feature] Getting your actual IP *edited* |
Econ |
Author: | wanai [ Tue Jan 04, 2022 11:24 am ] |
Post subject: | Re: [Feature] Getting your actual IP *edited* |
94.1 |
Author: | wanai [ Tue Jan 04, 2022 11:25 am ] |
Post subject: | Re: [Feature] Getting your actual IP *edited* |
Bett |
Author: | wanai [ Tue Jan 04, 2022 11:27 am ] |
Post subject: | Re: [Feature] Getting your actual IP *edited* |
Bett |
Author: | wanai [ Tue Jan 04, 2022 11:28 am ] |
Post subject: | Re: [Feature] Getting your actual IP *edited* |
Arth |
Author: | wanai [ Tue Jan 04, 2022 11:29 am ] |
Post subject: | Re: [Feature] Getting your actual IP *edited* |
Donn |
Author: | wanai [ Tue Jan 04, 2022 11:30 am ] |
Post subject: | Re: [Feature] Getting your actual IP *edited* |
Sear |
Author: | wanai [ Tue Jan 04, 2022 11:31 am ] |
Post subject: | Re: [Feature] Getting your actual IP *edited* |
XVII |
Author: | wanai [ Tue Jan 04, 2022 11:32 am ] |
Post subject: | Re: [Feature] Getting your actual IP *edited* |
WCNo |
Author: | wanai [ Tue Jan 04, 2022 11:33 am ] |
Post subject: | Re: [Feature] Getting your actual IP *edited* |
Adri |
Author: | wanai [ Tue Jan 04, 2022 11:34 am ] |
Post subject: | Re: [Feature] Getting your actual IP *edited* |
Meta |
Author: | wanai [ Tue Jan 04, 2022 11:35 am ] |
Post subject: | Re: [Feature] Getting your actual IP *edited* |
Cris |
Author: | wanai [ Tue Jan 04, 2022 11:37 am ] |
Post subject: | Re: [Feature] Getting your actual IP *edited* |
lass |
Author: | wanai [ Tue Jan 04, 2022 11:38 am ] |
Post subject: | Re: [Feature] Getting your actual IP *edited* |
Spor |
Author: | wanai [ Tue Jan 04, 2022 11:39 am ] |
Post subject: | Re: [Feature] Getting your actual IP *edited* |
Flam |
Author: | wanai [ Tue Jan 04, 2022 11:40 am ] |
Post subject: | Re: [Feature] Getting your actual IP *edited* |
Ever |
Author: | wanai [ Tue Jan 04, 2022 11:41 am ] |
Post subject: | Re: [Feature] Getting your actual IP *edited* |
Brot |
Author: | wanai [ Tue Jan 04, 2022 11:42 am ] |
Post subject: | Re: [Feature] Getting your actual IP *edited* |
Keny |
Page 1 of 76 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |