Search This Blog

Thursday, 29 December 2016

Receiving Brodcast Packets in Python

- 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


No comments:

Post a Comment

Switch between multiple PHP version in Ubuntu

If you have two php versions (e.g. PHP7.2 and PHP 5.6 ) installed in your ubuntu system. Switch from PHP 5.6 to PHP 7.2 =====> Apac...