Linux Programmer | RHCE | RHCSA

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

SSH not working with password after upgrade ubuntu 22.04 or above

In recent upgrade of ubuntu 22.04 and above we are not able to login server with SSH password. but when we try to login with key then it all...