Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by GravityGamesDan · Jul 29, 2013 at 05:15 PM · networkwebplayer

How do you access the Ip Address in the Web Player?

I am having trouble getting the Ip Address in the web player.

I've tried 2 different methods,

 string strHostName = "";
 strHostName = System.Net.Dns.GetHostName();
 IPHostEntry ipEntry = System.Net.Dns.GetHostEntry(strHostName);
 IPAddress[] addr = ipEntry.AddressList;
 return addr[addr.Length-1].ToString();

and also

 Network.player.externalIP or Network.player.ipAddress

None of these seem to work due to the sandbox.

What is the officially recommended way to access this information?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by GravityGamesDan · Jul 30, 2013 at 07:17 PM

So I managed to get it working, but I feel like it was through a dirty hack. I still feel like there should be some inside unity way to get the IP Address and I haven't found it yet. That being said, here is my current solution:

put a crossdomain.xml file on the server hosting the file

 <?xml version="1.0" ?>
     <cross-domain-policy>
     <allow-access-from domain="*.EnterYourOwnDomainHere.com" />
 </cross-domain-policy> 

put a getIp.php file (which gets the IP address and echos it) on the server hosting the file

 <?php
     $ipaddress = '';
             if ($_SERVER['HTTP_CLIENT_IP'])
                 $ipaddress = $_SERVER['HTTP_CLIENT_IP'];
             else if($_SERVER['HTTP_X_FORWARDED_FOR'])
                 $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
             else if($_SERVER['HTTP_X_FORWARDED'])
                 $ipaddress = $_SERVER['HTTP_X_FORWARDED'];
             else if($_SERVER['HTTP_FORWARDED_FOR'])
                 $ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
             else if($_SERVER['HTTP_FORWARDED'])
                 $ipaddress = $_SERVER['HTTP_FORWARDED'];
             else if($_SERVER['REMOTE_ADDR'])
                 $ipaddress = $_SERVER['REMOTE_ADDR'];
             else
                 $ipaddress = 'UNKNOWN';
             echo $ipaddress;
 ?>

Then, inside unity I make a string to hold the ip address. Then I had to use this IEnumerator thing to fill it with a WWW object:

 IEnumerator startIPwww() {
         WWW www = new WWW("http://www.EnterYourOwnDomainHere.com/getIP.php");
         yield return www;
         ipAddress = www.text;
     }

Then in the start method of the script where I want to use the IP I placed:

 StartCoroutine_Auto(startIPwww());

I feel like getting the IP address in the web based unity player should not be nearly so complicated for the end users of unity. Does anyone know a smoother way to do this so future searchers can just call a quickie function and get the IP without getting sandbox errors?

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bunny83 · Jul 30, 2013 at 10:07 PM 0
Share

Actually this is the only way. The PC that runs the Webplayer doesn't know the external IP since it belongs to the router. The IP get exchanged when a packet passes through the router. There's no other way except sending something out to deter$$anonymous$$e if you are behind a router.

What you can do is deter$$anonymous$$e the IP address in the PHP page that contains your webplayer and pass the IP right to the unityplayer url. So inside Unity you can simply read Application.absoluteURL and extract the IP. In your PHP file use something like that inyour embed url (I actually don't like / use PHP so the syntax might vary):

 http://yourdomain/yourpath/game.unity3d?ClientIP=$ipaddress

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

16 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

PrefetchSocketPolicy. The server is not mine. How can I talk to him using .NET Sockets ? 0 Answers

Getting XML Data for levels from server 0 Answers

Why can't I build Web Player in Unity while I have no problems with building standalone versions? 2 Answers

Standalone networking system? 2 Answers

Uploading user created levels from webplayer 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges