I am creating a packet sniffer (yes the hard way with socket) and using the following code:
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_TCP)
while True:
print(s.recvfrom(2048))
Which gives this error: OSError: [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions.
Through removing different things, I have determined that using a raw socket (socket.SOCK_RAW) is the issue, but there is no alternative to this. Can someone explain why I'm getting this error and how to get rid of it?
Make sure file is being run with admin.
Related
I am making an application using Eel for python, and it currently is a page with a button that opens up a second page. The first page is using port 8000, and when I open the second page I receive a message due to 8000 being in use. I have copied the message below.
OSError: [WinError 10048] Only one usage of each socket address (protocol/network address/port) is normally permitted: ('localhost', 8000)
I have gotten this message to disappear by changing the port of the second window to 8001. Is this a preferable fix? I plan on having more than 2 windows eventually, so each window would use a different port. I have found similar issues that are fixed by changing the socket option "SO_REUSEADD", but I am not sure how to do this using eel, is it possible? What would be the best way to handle this, could I just ignore it?
i'am using this code to connect with a module of ip address 20.20.20.170 but i'm not able to do. I've used all socket programming codes but no one is working. Remember i have to only receive data. Can any one help me to resolve this problem
code is here...
import socket
TCP_IP='20.20.20.170'
TCP_PORT=20108
buffer_size=1024
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect((TCP_IP,TCP_PORT))
output=s.recv(1024)
print(output)
s.close()
print("received data:",data)
I am trying to connect a client machine to a server mashine in different network using PYRO4 and Python 2.7
My server code is:
import Pyro4
class Thing(object):
def method(self, arg):
return arg*2
daemon=Pyro4.Daemon(port=9999,nathost="78.149.X.X", natport=5555)
uri=daemon.register(Thing(),"gameServer") # register Thing() as a Pyro object
print "Ready. Object uri =", uri
daemon.requestLoop()
and the client code is:
import Pyro4
server = Pyro4.Proxy("PYRO:gameServer#78.149.X.X:5555")
print server.method(6)
However, when I ran the server, I got this error:
CommunicationError: cannot connect: [Errno 10061] No connection could be made because the target machine actively refused it
I am searching since 8 hours to fix this issue but it seems it will not be fixed forever. Please if anybody know the solution please help me.
NOTE:
1. I am rannig the server behind a router, so I forworded the port 5555 to my private IP address. Also, I tested the port by an online service and its opend correctly.
I closed the firewall and the antivirus software.
Have you tried all the suggestions mentioned in the manual?
Your daemon simply is not accessible on the address that you think it is. Perhaps you need to add an appropriate binding host to the daemon constructor call, to bind it on the network interface that is accessible from the outside.
Also try to eliminate possible causes one by one and see which one is the culprit. For instance, have you tried to run it without the router in between?
I am trying to make a very basic FTP client in python, and within the first few lines of code I have already run into a problem
My Code:
from ftplib import FTP
ftp = FTP('ftp.mysite.com')
With this code, and with countless different urls used, I will always get the same error:
gaierror: [Errno 11004] getaddrinfo failed
I found myself here with this error trying to connect using the full path rather than just the hostname. Make sure you split that out and use cwd(path) after login().
For example:
ftp = FTP('ftp.ncdc.noaa.gov')
ftp.login()
ftp.cwd('pub/data/noaa/2013')
instead of:
# Doesn't work!!
ftp = FTP('ftp.ncdc.noaa.gov/pub/data/noaa')
ftp.login()
ftp.cwd('2013')
Kind of obvious in hindsight, but hopefully I help you notice your simple mistake!
Actually, this means that your computer can't resolve the domain name that you gave it. A detailed error description is available here. Try to use a well-known working FTP to test (e.g. ftp.microsoft.com). Then try to open the FTP you're trying to access with some FTP client.
I'm trying to make an online FPS game and so far it works on my local network. What I'm trying to do is make it work globally
I've tried making other Python projects work globally in the past but so far I haven't been able to get it to work. I get my IP from ipchicken or whatever and put it as the HOST for the server, but when I try to start it I get this.
socket.error: [Errno 10049] The requested address is not valid in its context
I've tried many different versions of what could be my IP address found from various different places, but all of them give that output.
I thought, since I had my webspace, I could try doing what it says you can do in the Python manual:
where host is a string representing either a hostname in Internet domain notation like 'daring.cwi.nl'
So, I put in the domain of my webspace (h4rtland.p3dp.com) and I get this error:
socket.error: [Errno 10048] Only one usage of each socket address (protocol/network address/port) is normally permitted
Though only on port 80, anything else gives me the same error as before.
If anybody can shed some light on this subject for me it would be greatly appreciated.
First off, port 80 is typically http traffic. Anything under port 5000 is priviledged which means you really don't want to assign your server to this port unless you absolutely know what you are doing... Following is a simple way to set up a server socket to accept listen...
import socket
host = None #will determine your available interfaces and assign this dynamically
port = 5001 #just choose a number > 5000
for socket_information in socket.getaddrinfo(host, port, socket.AF_INET, socket.SOCK_STREAM):
(family, type, prototype, name, socket_address) = socket_information
sock = socket.socket(family, type, prototype)
sock.bind(socket_address)
max_clients = 1
sock.listen(max_clients)
connection, address = sock.accept()
print 'Client has connected:', address
connection.send('Goodbye!')
connection.close()
This is a TCP connection, for an FPS game you likely want to look into using UDP such that dropped packets don't impact performance terribly... Goodluck