Need help with a script to track IPs

Please tell me the script, if any user ping my pc so leave his ip, mac and other identity on my pc.

There is no "the script". What operating system is your PC running?
There are several tools for different operating systems to track connections.

Maybe get Wireshark for example, which is also available for several OSes.

Else as a start, maybe write a loop that triggers netstat which is available on most OS and writes the output to a file.
Show what you have tried and we can help maybe.