- Receive Brodcast Packets in Python Without Configuring Network (Network cable connection needed )
Sending Packets
import os
import sys
import commands
from socket import *
macid = commands.getoutput('ifconfig | grep -i hwaddr | head -1')
os.system("echo '%s' | awk '{print$5}' >/tmp/.mac"%macid)
mac = commands.getoutput('cat /tmp/.mac')
hostname = commands.getoutput('hostname')
username = commands.getoutput('whoami')
info = "connect:"+'%s?%s?%s'%(username,mac,hostname)
s=socket(AF_INET, SOCK_DGRAM)
s.setsockopt(SOL_SOCKET, SO_BROADCAST, 1)
s.sendto(info,('255.255.255.255',12345))
Receiving Packets
from socket import *
count = 0
while (count < 100):
s=socket(AF_INET, SOCK_DGRAM)
s.bind(('',12345))
m=s.recvfrom(1024)
print m[0]
count = count + 1
Sending Packets
import os
import sys
import commands
from socket import *
macid = commands.getoutput('ifconfig | grep -i hwaddr | head -1')
os.system("echo '%s' | awk '{print$5}' >/tmp/.mac"%macid)
mac = commands.getoutput('cat /tmp/.mac')
hostname = commands.getoutput('hostname')
username = commands.getoutput('whoami')
info = "connect:"+'%s?%s?%s'%(username,mac,hostname)
s=socket(AF_INET, SOCK_DGRAM)
s.setsockopt(SOL_SOCKET, SO_BROADCAST, 1)
s.sendto(info,('255.255.255.255',12345))
Receiving Packets
from socket import *
count = 0
while (count < 100):
s=socket(AF_INET, SOCK_DGRAM)
s.bind(('',12345))
m=s.recvfrom(1024)
print m[0]
count = count + 1
No comments:
Post a Comment