I am trying to make something like a firewall but it isnt a firewall it is just suppose to see all the incomming and outgoing connections of each port. And put the IP address and port into a .txt file. Basicly creating a log of incomming and outgoing connections.

Nothing fancy, just that.

How do i do this?

Like Wireshark. It's an open-source project, so feel free to check out its source code and learn from it.

While Wireshark is a great tool I, think it is a little hard to digest for something as simple as grabbing packets. It is probably easier to concentrate on the underlying libpcap to get started and move up from there.