0

I am a newbie to Python and looking for assistance how possible this is. I am looking for a way to do a lookup of IP Address that is in one file and do a lookup of where that IP Subnet is based on another file:

Device IP Address File:

Device | IP Address

-------- | ------------

Server 1 | 1.1.1.1

Server 2 | 2.2.2.2

Server 3 | 3.3.3.3

Computer 1 | 4.4.4.4

Computer 2 | 5.5.5.5

Computer 3 | 6.6.6.6

Computer 4 | 7.7.7.7

Subnet File:

network | cidr | type | Location

---------- | ---- | ----- | -----------

1.1.1.0 | /23 | network | Data Center - Zone 1

2.2.2.0 | /23 | network | Data Center - Zone 2

3.3.3.0 | /21 | network | Data Center - Zone 3

4.4.4.0 | /21 | network | Office Location 1

5.5.5.0 | /23 | network | Office Location 2

6.6.6.0 | /28 | network | Office Location 3

7.7.7.0 | /31 | network | Office Location 4

8.8.8.0 | /31 | network | Office Location 5

What I am trying to do is get create a python script that will read Device IP Address from one file and do a lookup of location based on subnet of that IP Address that is listed in subnet file and output results to a new file:

Output File:

Device | IP Address | Location

-------- | ------------ | -----------

Server 1 | 1.1.1.1 | Data Center - Zone 1

Server 2 | 2.2.2.2 | Data Center - Zone 2

Server 3 | 3.3.3.3 | Data Center - Zone 3

Computer 1 | 4.4.4.4 | Office Location 1

Computer 2 | 5.5.5.5 | Office Location 2

Computer 3 | 6.6.6.6 | Office Location 3

Computer 4 | 7.7.7.7 | Office Location 4

Currently these files are in XLSX format but can easily convert to another format if easier.

rlugones
  • 1
  • 2
  • Please edit your question to show the desired file structure (in and out). – msitt Apr 27 '17 at 14:14
  • you can ignore the "|" in file format – rlugones Apr 27 '17 at 14:36
  • Already been asked I think [look here](https://stackoverflow.com/questions/1163136/how-to-detect-the-country-and-city-of-a-user-accessing-your-site) You'll have to do some getting of IPs out of files into a structure but that should be easy with Python. – Khushil Apr 27 '17 at 14:07
  • This is not really what I was looking to do. I have the two files. I am trying to decipher location within my Internal network... I think the challenge with what I am looking to do is understand from my subnet file code needed to understand range of IP Addresses based on CIDR – rlugones Apr 27 '17 at 15:11

0 Answers0