# How to get the host name and ip

**URL:** https://community.wowza.com/t/how-to-get-the-host-name-and-ip/34538
**Category:** Wowza Streaming Engine
**Created:** [June 6, 2012, 10:17am UTC](https://community.wowza.com/t/how-to-get-the-host-name-and-ip/34538 "2012-06-06T10:17:40Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![Graeme\_Bull](https://avatars.discourse-cdn.com/v4/letter/g/cc9497/32.png) [@Graeme\_Bull](https://community.wowza.com/u/Graeme_Bull)
#### Post date: [June 6, 2012, 10:17am UTC](https://community.wowza.com/t/how-to-get-the-host-name-and-ip/34538/1 "2012-06-06T10:17:40Z")

</div>

I’ve done some searching, gone through the docs and played around and it’s not obvious to me so I thought I would quickly ask in case somebody knows.

How do I get the host name and IP of the host server of Wowza through server side code? I want to get these values on the application start (onAppStart)

Thanks

Graeme

---

<div class="post-metadata">

### Author: ![Richard\_Lanham](https://avatars.discourse-cdn.com/v4/letter/r/c68b51/32.png) [@Richard\_Lanham](https://community.wowza.com/u/Richard_Lanham)
#### Post date: [June 6, 2012, 6:26pm UTC](https://community.wowza.com/t/how-to-get-the-host-name-and-ip/34538/2 "2012-06-06T18:26:43Z")

</div>

You could set them in Application.xml Property settings. I don’t think Wowza has a way of knowing what hostname a server is reachable through, or the IP addresses, unless they are set in a VHost /HostPort /IpAddress, in which case there is probably some way.

Richard

---

<div class="post-metadata">

### Author: ![Charlie\_Good](https://sea2.discourse-cdn.com/flex002/user_avatar/community.wowza.com/charlie_good/32/383_2.png) [@Charlie\_Good](https://community.wowza.com/u/Charlie_Good)
#### Post date: [June 6, 2012, 11:03am UTC](https://community.wowza.com/t/how-to-get-the-host-name-and-ip/34538/3 "2012-06-06T11:03:03Z")

</div>

From the vhost interface you can get the list of HostPorts:

```auto
HostPortList hostPortList = appInstance.getVHost().getHostPortsList();

```

Charlie

---

<div class="post-metadata">

### Author: ![Richard\_Lanham](https://avatars.discourse-cdn.com/v4/letter/r/c68b51/32.png) [@Richard\_Lanham](https://community.wowza.com/u/Richard_Lanham)
#### Post date: [June 6, 2012, 7:05pm UTC](https://community.wowza.com/t/how-to-get-the-host-name-and-ip/34538/4 "2012-06-06T19:05:41Z")

</div>

Yes, setting a Property in a VHost.xml or Server.xml will work to avoid maintaining per app

Richard

---

<div class="post-metadata">

### Author: ![Richard\_Lanham](https://avatars.discourse-cdn.com/v4/letter/r/c68b51/32.png) [@Richard\_Lanham](https://community.wowza.com/u/Richard_Lanham)
#### Post date: [June 6, 2012, 8:12pm UTC](https://community.wowza.com/t/how-to-get-the-host-name-and-ip/34538/5 "2012-06-06T20:12:07Z")

</div>

You can use a hostname in HostPort /IpAddress, and you can get all HostPorts in Charlie’s example, then you should be able to look at each HostPort IpAddress. If it is set using a hostname you can get that.

```auto
HostPortList hostPortList = appInstance.getVHost().getHostPortsList();
for (int i=0;i<hostPortList.size();i++)
{
	HostPort port =hostPortList.get(i);
	String ip = port.getAddressStr();
}		

```

---

<div class="post-metadata">

### Author: ![Richard\_Lanham](https://avatars.discourse-cdn.com/v4/letter/r/c68b51/32.png) [@Richard\_Lanham](https://community.wowza.com/u/Richard_Lanham)
#### Post date: [June 6, 2012, 8:50pm UTC](https://community.wowza.com/t/how-to-get-the-host-name-and-ip/34538/6 "2012-06-06T20:50:14Z")

</div>

I think this means you have the default “_" in the HostPort IpAddress fields, i.e., any IP address. The suggestion is to replace the "_” with a hostname (that resolves to a ip on that machine), then it should show up.

Richard

---

<div class="post-metadata">

### Author: ![Graeme\_Bull](https://avatars.discourse-cdn.com/v4/letter/g/cc9497/32.png) [@Graeme\_Bull](https://community.wowza.com/u/Graeme_Bull)
#### Post date: [June 6, 2012, 10:36am UTC](https://community.wowza.com/t/how-to-get-the-host-name-and-ip/34538/7 "2012-06-06T10:36:39Z")

</div>

I was wondering if I would need to do that. That sucks, I would have rather it be dynamic so that I don’t have to make a custom Application.xml file for every server we have.

---

<div class="post-metadata">

### Author: ![Graeme\_Bull](https://avatars.discourse-cdn.com/v4/letter/g/cc9497/32.png) [@Graeme\_Bull](https://community.wowza.com/u/Graeme_Bull)
#### Post date: [June 6, 2012, 11:26am UTC](https://community.wowza.com/t/how-to-get-the-host-name-and-ip/34538/8 "2012-06-06T11:26:03Z")

</div>

Yes, I realize I _can_ do that, but I didn’t want to. It would be awesome if I could just get it dynamically.

Feature request!! 🙂

---

<div class="post-metadata">

### Author: ![Graeme\_Bull](https://avatars.discourse-cdn.com/v4/letter/g/cc9497/32.png) [@Graeme\_Bull](https://community.wowza.com/u/Graeme_Bull)
#### Post date: [June 6, 2012, 12:38pm UTC](https://community.wowza.com/t/how-to-get-the-host-name-and-ip/34538/9 "2012-06-06T12:38:54Z")

</div>

Thanks Richard. When I output it I get:

INFO server comment - ip: + [any]

INFO server comment - ip: + [any]

Getting there. I think for now I’ll stick it in the vhost xml file. It’s not too bad of a solution.

---

<div class="post-metadata">

### Author: ![Jay\_Charles](https://avatars.discourse-cdn.com/v4/letter/j/c89c15/32.png) [@Jay\_Charles](https://community.wowza.com/u/Jay_Charles)
#### Post date: [June 6, 2012, 1:59pm UTC](https://community.wowza.com/t/how-to-get-the-host-name-and-ip/34538/10 "2012-06-06T13:59:38Z")

</div>

Couldn’t you just define those values as properties in Vhost.xml, and then read them using application.getVhost.getProperties() ?
