• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

Code to check IP address in XML file

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have an XML file like this . I want to check an IP , say 172.31.1.47 or 192.39.1.89 which is the IP of the client and check whihc range (defined in begin and end tag of nodes) .

Say for an example, Ip 172.31.1.47 falls inside <begin> and<end> value 172.31.1.1 - 172.31.1.254 once it verifies these, it will retrieve all the other attributes of the node.

<?xml version="1.0"?>

<project>
<AppA>
<begin>172.31.1.1</begin>
<end>172.31.1.254</end>
<attribute1>275</attribute1>
</AppA>
<AppB>
<begin>192.39.1.1</begin>
<end>192.39.1.254</end>
<attribute1>285</attribute1>
</AppB>
</project>

Tell me is there any logic to check whether an Ip falls under the begin and end tag Ip address values.
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can convert the ip address in to a 32-bit value. For instance, each tuple in the IP address will be represented as one byte. Once converted, you can do simply integer comparison to see whether a specific IP address falls within a specific range.

For example:

192.168.111.200 = 11000000 10101000 11011111 11001000

Originally posted by Prasann Mathur:
I have an XML file like this . I want to check an IP , say 172.31.1.47 or 192.39.1.89 which is the IP of the client and check whihc range (defined in begin and end tag of nodes) .

Say for an example, Ip 172.31.1.47 falls inside <begin> and<end> value 172.31.1.1 - 172.31.1.254 once it verifies these, it will retrieve all the other attributes of the node.

<?xml version="1.0"?>

<project>
<AppA>
<begin>172.31.1.1</begin>
<end>172.31.1.254</end>
<attribute1>275</attribute1>
</AppA>
<AppB>
<begin>192.39.1.1</begin>
<end>192.39.1.254</end>
<attribute1>285</attribute1>
</AppB>
</project>

Tell me is there any logic to check whether an Ip falls under the begin and end tag Ip address values.

reply
    Bookmark Topic Watch Topic
  • New Topic