Q:

socket.error: [Errno 49] Can't assign requested address

so i recently bought Black hat hacking with python on humblebundle
but i've kinda hit a brick wall and i hope someone can help or explain to me why this is happening:
my platform is osx macbook more specifily mjlt2
import socket
import os

# host to listen on
host = "192.168.1.190"

# create raw socket and bind it to public interface
if os.name == "nt":
    socket_protocol = socket.IPPROTO_IP
else:
    socket_protocol = socket.IPPROTO_ICMP

sniffer = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket_protocol)

sniffer.bind((host, 0))

# we want the IP headers included in the capture
sniffer.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)

# if we're using windows need to send an IOCTL
# to set up promiscous mode
if os.name == "nt":
    sniffer.ioctl(socket.SIO_RCVALL, socket.RCVALL_ON)

# read in a single packet
print(sniffer.recvfrom(65565))

# if we're using window, turn off promiscuous mode
if os.name == "nt":
    sniffer.ioctl(socket.SIO_RCVALL, socket.RCVALL_OFF)

now this is the authors explanation of what the code dos and what to expect...
We start by constructing our socket object with the parameters nec- essary for snif ng packets on our network interfaceu. The difference between Windows and Linux is that Windows will allow us to sniff all incoming packets regardless of protocol, whereas Linux forces us to spec- ify that we are snif ng ICMP. Note that we are using promiscuous mode, which requires administrative privileges on Windows or root on Linux. Promiscuous mode allows us to sniff all packets that the network card sees, even those not destined for your speci c host. Next we set a socket optionv that includes the IP headers in our captured packets. The next stepwis to determine if we are using Windows, and if so, we perform the additional step of sending an IOCTL to the network card driver to enable promiscu- ous mode. If you’re running Windows in a virtual machine, you will likely get a noti cation that the guest operating system is enabling promiscuous mode; you, of course, will allow it. Now we are ready to actually perform some snif ng, and in this case we are simply printing out the entire raw packetxwith no packet decoding. This is just to test to make sure we have the core of our snif ng code working. After a single packet is sniffed, we again test for Windows, and disable promiscuous modeybefore exiting the script.
and my understanding of this is that i should be able to use this on nostarch.com as an example
but the only thing that comes back to me is:
sniffer.bind((host, 0))
OSError: [Errno 49] Can't assign requested address

except if i try it on myself
i cant use it on the router, or on my local appleTv or, smartv i only get a response when i ping my self
can anyone tell my i can only ping myself with this chunk of code? is it to be expected or is it something with my network card or?
// Alexander
BTW if you see this Justin Seitz Your awsome! great book!

A:

okay this is somewhat embarrassing....
i guess i misunderstood what the code did!
if anyone else should come by this following the same book have the same question the answer is:
host = "my local ip adress"

it will only listen to local assiged adress
and then return what its supposed to based what i do next
if i open my browser and enter google.com the script checks google.com and return the raw ip header
if i open an other terminal and ping some site or ip it returns the raw ip header of that
hope this helps someone
//Alexander  # Take care everyone

