Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help, My code seems to not work Step 1 : Download the compressed table DB_091803_v1.txt and test input file: IPlist.txt. Upload them to your

Need help, My code seems to not work

Step 1: Download the compressed table DB_091803_v1.txt and test input file: IPlist.txt. Upload them to your Colab space using the code below.

from google.colab import files

uploaded = files.upload()

DB = next(iter(uploaded))

print(DB, "uploaded")

uploaded = files.upload()

IP_LIST = next(iter(uploaded))

print(IP_LIST, "uploaded")

Step 2: Develop the IP2AS tool - This tool maps an IP address to an AS. It uses static table address prefix to AS number collected from whois DB and BGP tables. This table is stored in a file and should be given to the tool as a parameter. It will perform longest prefix matching and will map the IP to an AS number. The tool should print out the longest prefix that the IP address is matched to, and the corresponding AS number.

Steps:

1. Put the set of IP addresses you want to map to ASes into the . You can list one IP address per line.

For example, look at IPlist.txt file, which contains the following:

 169.237.33.90 208.30.172.70

2. The has data about which address block belongs to a particular AS (look at DB_091803_v1.txt file, for example). The is constructed based on IRR database and BGP routing table.

3. Run ip2as and specify the and

For example, if you run your code, the output should look like the following:

169.237.0.0/16 1852 169.237.33.90 208.0.0.0/11 1239 208.30.172.70

My code is below:

import socket

import struct

def ip2as(ip, prefix_asn_list):

ip_num = struct.unpack("!I", socket.inet_aton(ip))[0]

max_prefix = 0

max_prefix_asn = None

for prefix, asn in prefix_asn_list:

if prefix <= ip_num < prefix + (1 << 32 - prefix.bit_length()):

if prefix > max_prefix:

max_prefix = prefix

max_prefix_asn = asn

return max_prefix, max_prefix_asn

def read_db_file(filename):

prefix_asn_list = []

with open(filename) as f:

for line in f:

prefix, asn = line.strip().split()

prefix = struct.unpack("!I", socket.inet_aton(prefix))[0]

prefix_asn_list.append((prefix, int(asn)))

return prefix_asn_list

def main(db_filename, input_filename):

prefix_asn_list = read_db_file(db_filename)

with open(input_filename) as f:

for line in f:

ip = line.strip()

prefix, asn = ip2as(ip, prefix_asn_list)

prefix = socket.inet_ntoa(struct.pack("!I", prefix))

print(f"{prefix}/{32 - prefix.bit_length()} {asn} {ip}")

if __name__ == "__main__":

db_filename = "DB_091803_v1.txt"

input_filename = "IPlist.txt"

main(db_filename, input_filename)

This is the error I keep seeing

Traceback (most recent call last): File "C:/Users/varun/Desktop/P/MS/CN/ip2as2.py", line 36, in main(db_filename, input_filename) File "C:/Users/varun/Desktop/P/MS/CN/ip2as2.py", line 25, in main prefix_asn_list = read_db_file(db_filename) File "C:/Users/varun/Desktop/P/MS/CN/ip2as2.py", line 19, in read_db_file prefix, asn = line.strip().split() ValueError: too many values to unpack (expected 2)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Spatial Databases 2nd Symposium Ssd 91 Zurich Switzerland August 1991 Proceedings Lncs 525

Authors: Oliver Gunther ,Hans-Jorg Schek

1st Edition

3540544143, 978-3540544142

More Books

Students also viewed these Databases questions

Question

State the uses of job description.

Answered: 1 week ago

Question

Explain in detail the different methods of performance appraisal .

Answered: 1 week ago

Question

Explain basic guidelines for effective multicultural communication.

Answered: 1 week ago

Question

Identify communication barriers and describe ways to remove them.

Answered: 1 week ago

Question

Explain the communication process.

Answered: 1 week ago