This is federally illegal, unless your country is part of the Visa Waiver Program or you have a U.S. hunting license.
18 USC § 922(g)(5)(B) states:
(g) It shall be unlawful for any person—
(5) who, being an alien—
(B) except as provided in subsection (y)(2), has been admitted to the United States under a nonimmigrant visa...
If you have been admitted to the United States under a nonimmigrant visa, it is a federal offense to possess a firearm. The relevant exception in section (y)(2) is admission for "sporting purposes" (that is, you entered specifically to hunt or to attend a shooting competition) or having a hunting license.
The ATF confirms that this does not apply to countries that do not require visas:
Does the prohibition on the receipt and possession of firearms and ammunition by aliens in nonimmigrant visa status apply to nonimmigrant aliens who lawfully enter the United States without a visa?
No. A nonimmigrant alien who is lawfully admitted to the United States without a visa (e.g. Visa Waiver Program), may acquire or possess a firearm in the United States.
Even if you have one of the above exceptions, beware that no party may legally permanently transfer a firearm to you.
18 USC § 922(b)(3) states:
(b) It shall be unlawful for any licensed importer, licensed manufacturer, licensed dealer, or licensed collector to sell or deliver—
(3) any firearm to any person who the licensee knows or has reasonable cause to believe does not reside in...the State in which the licensee’s place of business is located, except that this paragraph (A) shall not apply to the sale or delivery of any rifle or shotgun to a resident of a State other than a State in which the licensee’s place of business is located...and (B) shall not apply to the loan or rental of a firearm to any person for temporary use for lawful sporting purposes
Section (a)(3) says the same of private parties. Because you do not reside in any State, exception (A) does not apply to you, and a party may transfer a firearm to you only under exception (B), i.e. temporarily for lawful sporting purposes.
There is also section (a)(9), which prohibits people who do not reside in any state from receiving firearms other than for lawful sporting purposes. This should not affect you, as a shooting range definitely qualifies as lawful sporting purposes.