# Verify IP address

**URL:** <https://forum.inductiveautomation.com/t/verify-ip-address/77811>\
**Category:** Ignition\
**Created:** [August 14, 2023, 3:15pm UTC](https://forum.inductiveautomation.com/t/verify-ip-address/77811 "2023-08-14T15:15:11Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![rfolkes](https://avatars.discourse-cdn.com/v4/letter/r/e95f7d/32.png) [@rfolkes](https://forum.inductiveautomation.com/u/rfolkes)\
**Post date:** [August 14, 2023, 3:15pm UTC](https://forum.inductiveautomation.com/t/verify-ip-address/77811/1 "2023-08-14T15:15:11Z")

</div>

> **[ipaddress — IPv4/IPv6 manipulation library](https://docs.python.org/3/library/ipaddress.html?highlight=ipaddress#module-ipaddress)**
>
> Source code: Lib/ipaddress.py ipaddress provides the capabilities to create, manipulate and operate on IPv4 and IPv6 addresses and networks. The functions and classes in this module make it straigh...

I want to validate an IP address and found this. Import doesn't seem to work so I tried just copy the code into Project Library [https://github.com/python/cpython/blob/3.11/Lib/ipaddress.py](https://github.com/python/cpython/blob/3.11/Lib/ipaddress.py) but that doesn't seem to work either.

I'm guessing it is because this is 3.3 and ignition runs 2.7 python version.

Is there something that works in 2.7?

main function I am looking for is something that takes a string and verifies it is a valid IP address IPV4.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [August 14, 2023, 3:31pm UTC](https://forum.inductiveautomation.com/t/verify-ip-address/77811/2 "2023-08-14T15:31:00Z")

</div>

Generally, you'd pass whatever you have to `java.net.InetAddress.getByName()`, and then check if you got an instance of `Inet4Address`. As a side benefit, it will look up a provided hostname, too.

---

<div class="post-metadata">

**Author:** ![rfolkes](https://avatars.discourse-cdn.com/v4/letter/r/e95f7d/32.png) [@rfolkes](https://forum.inductiveautomation.com/u/rfolkes)\
**Post date:** [August 14, 2023, 3:51pm UTC](https://forum.inductiveautomation.com/t/verify-ip-address/77811/4 "2023-08-14T15:51:14Z")

</div>

```auto
import java
ipaddress = "162.2.2.999"

try:
	java.net.InetAddress.getByName(ipaddress)
except:	
	print "no good"
else: 
	print "good"

```

looks like that works. Thanks.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [August 14, 2023, 3:57pm UTC](https://forum.inductiveautomation.com/t/verify-ip-address/77811/5 "2023-08-14T15:57:31Z")

</div>

Holy Moly, don't do that. You're importing all of the java "name space".

Like this:

```auto
from java.net import InetAddress
ipaddress = '162.2.2.999'
try:
   InetAddress.getByName(ipaddress)
   print 'good'
except:
   print 'no good'

```

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [August 14, 2023, 4:17pm UTC](https://forum.inductiveautomation.com/t/verify-ip-address/77811/6 "2023-08-14T16:17:33Z")

</div>

Uhm, you said you wanted to check for an IPv4 address. The above will allow IPv6 addresses. Use this:

```auto
from java.net import InetAddress, Inet4Address
ipaddress = '162.2.2.999'
try:
   addr = InetAddress.getByName(ipaddress)
   if isinstance(addr, Inet4Address):
      print 'good'
   else:
      print 'not IPv4'
except:
   print 'no good'

```

---

<div class="post-metadata">

**Author:** ![rfolkes](https://avatars.discourse-cdn.com/v4/letter/r/e95f7d/32.png) [@rfolkes](https://forum.inductiveautomation.com/u/rfolkes)\
**Post date:** [August 14, 2023, 4:25pm UTC](https://forum.inductiveautomation.com/t/verify-ip-address/77811/7 "2023-08-14T16:25:19Z")

</div>

thanks

---

<div class="post-metadata">

**Author:** ![boddupalli\_subbarao](https://avatars.discourse-cdn.com/v4/letter/b/8e8cbc/32.png) [@boddupalli\_subbarao](https://forum.inductiveautomation.com/u/boddupalli_subbarao)\
**Post date:** [February 27, 2024, 12:47pm UTC](https://forum.inductiveautomation.com/t/verify-ip-address/77811/8 "2024-02-27T12:47:23Z")

</div>

Great ,  
It is working...
