Unless you use set_bind_ip()
its really only the port number that matters
And good old error checking is the way to resolve your issue
var check = peer.create_server(lan_port)
if check == ERR_ALREADY_IN_USE:
use_another_port()
So maybe have a loop like this
var lan_port = 8080
func connect_server(lan_port : int):
var check = peer.create_server(lan_port)
if check == ERR_ALREADY_IN_USE:
if lan_port < 8090: #prevent infinite loop
lan_port += 1
connect_server(lan_port)
get_tree().set_network_peer(peer)