Hi all,
I am writing code for finding source address of packets, so that i discard them if the ipaddress is not a valid one. For this, i think i have to make a raw socket and continuously sniff the network. Now, if any packet arrives, how to catch the packet and retrieves information from its header.

Please help me with a proper solution.

Thanks in advance.:)

It would depend a little on the connection you make. If its TCP based then refuse the connection based on IP, if its UDP eg connectionless then yes, each received packet would have to be ignored or used depending on wether it fits.

Network sniffing is generally frowned on as companies can be sued by employees if they havent been notified that network sniffing is being used as their private data is considered at risk, even though its company machines.

Any connection to your machine comes as part of the packet where it came from so you can reply.

Thank you very much..

Can I read router databases in my C# applications. If yes, which databases of router i can read ?

Depends on your router, Im not aware of any routers that have databases in programming terms. They have config files, and memory, and you can access them either by ssh or telnet, run commands to return various datas such as links up/down/config/errors etc. you can then parse that and display it in anyway you see fit.