Networks and the web · A level · AQA 7517 4.9.4.7 · about 30 min
How a device gets its address, and how a router shares one public address with a whole network.
[1 mark]Put the DHCP messages in the order they are sent.
Number the lines 1 to 4 to put them in the right order.
OfferAcknowledgeDiscoverRequestDiscover Offer Request Acknowledge
The client discovers a server, the server offers an address, the client requests it, and the server acknowledges the lease.
[1 mark]Which settings does a DHCP server typically give a device? Choose all that apply.
Tick every answer that is true.
[1 mark]When a packet leaves a home network through a router using NAT, what does the router change?
[1 mark]Why is NAT used? Choose all that apply.
Tick every answer that is true.
[1 mark]A student runs a game server at 192.168.1.40 on their home network. What lets friends on the Internet connect to it?
[1 mark]What does this program print?
table = {}
next_port = 50000
for socket in ['192.168.1.5:3000', '192.168.1.6:3000', '192.168.1.5:3000']:
if socket not in table:
table[socket] = next_port
next_port = next_port + 1
print(socket, '->', table[socket])192.168.1.5:3000 -> 50000 192.168.1.6:3000 -> 50001 192.168.1.5:3000 -> 50000
Each new private socket gets the next public port; the repeated socket reuses its existing entry.
The Router on this mat is a DHCP server that talks over the radio in a simplified form of DORA. Messages are words separated by single spaces.
1. Send DISCOVER.
2. The Router replies OFFER <address> <mask> <gateway> <lease seconds>. Print offered <address>.
3. Send REQUEST <address>, using the address from the offer.
4. The Router replies ACK <address> <mask> <gateway> <lease seconds>. From the ACK, print address: <address>, then gateway: <gateway>, then lease: <hours> hours, where hours is the lease in seconds divided by 3600 as a whole number.
Check messages() every 0.1 s while you wait for each reply. Read every value from the replies; the robot does not drive.
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
send("DISCOVER")
wait(1)
print(messages())The hint students can ask for: Write one helper that waits for a reply starting with a given word and hands back its fields. Use it after each message you send. The offer tells you what to request; only the acknowledgement makes the address yours, so print the settings from that.
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
def wait_for(word):
while True:
wait(0.1)
for sender, text in messages():
fields = text.split()
if fields[0] == word:
return fields
send("DISCOVER")
offer = wait_for("OFFER")
print("offered", offer[1])
send("REQUEST " + offer[1])
ack = wait_for("ACK")
print("address:", ack[1])
print("gateway:", ack[3])
print("lease:", int(ack[4]) // 3600, "hours")
Any program that meets the task's checks is marked correct in the simulator; this is one way, not the only way.