Added socket import for ip validity checks