There are two IP addresses associated with a packet, the sending (also know as source) IP and destination IP.
Sending IP - The sending IP is trivial, it is a configuration parameter of the network interface by which the packet will be transmitted. It is configured either statically or more typically in modern networks through DHCP.
Destination IP - The destination IP can be slightly more complex depending upon whether the destination computer is local or remote to the sending computer. In this case, remote means that the destination computer is not located in the same subnet as the source computer.
For remote destinations DNS servers are used for name<->IP resolution. DNS is what allows humans to use our strength, names such as www.espn.com, while computer can use their strength, bit representation of IP addresses such as 10.5.0.1. DNS resolution can be configured many different ways, but basically boils down to examining local cache to see if a prior resolution exists, and if not querying one or more DNS servers to resolve the request.
If the destination machine is local, on the same subnet, then ARP/RARP is used for MAC<->IP translation. Once again a cache is checked first, in this case the ARP cache, before creating a new ARP request (and thereby using network bandwidth).
I hope this helps.