Recently i was asked a question in an interview which i couldn't do. Anyone got a solution for this?
Grab all connected IP´s on the Linux machine
check every connected IP if TCP port 1706 is open
if its open > execute command. CURL ‘http:// some address ’
Else do nothing.
program will check this every 60 minits
Plattform Linux Ubuntu Server 12. X64 / x32
WAP in C++
Thanks!!
Make a bash script.
LOGIC:
Use
netstat -natp(filter it throughawk/sedto get the ports, then grep it) Then use a simple test to see if the result was empty. Runcurlif it was.Put this in a cron job. Simple stuff, really.
EDIT:
netstatis a utility which will show you all of the connections on your computer.netstat -natpshows a list of the programs which have tcp sockets on your computer.sedandawkare used for text formatting. You can use them to list a specific column.grepsearches input to find a specified string.bash allows for basic logic, and can be used to see if a string is empty.
cronis a linux process which schedules commands to be run at certain times.EDIT #2:
You COULD poll
/proc/net/tcp, but sincenetstatdoes that and formats it nicely, why bother?