The Japanese traded with the Dutch, Koreans, and Ainu, as well as semi unofficially using them and the Ryukyus to trade with everyone else. The Japanese translated, compiled, and published history books on the outside world even within years before Perry. They used Nanban and Dutch Learning and the government made sure to compile all new information they found. Before the closing of Japan they had more guns (and quite well made) than France or any other country in the world. If the Shogun claimed there was no need for foreign trade he would have been liking. That was how the Lords of the South got much of their income, as did he. Through keeping trade limited so that it all went into their coffers and they could control prices for the populace, while also giving foreigners bad prices, as well as using them to trade with China, which would not do it directly because of them refusing to recognize the Chinese system (that, and the Chinese hadn't originally been happy about all the Pirate Dwarfs that attacked them before the Seclusion). When the Japanese were going to threaten the Dutch to cut off or limit trade, they first checked with the port dealing with the Koreans, seeing if they could double imports so that there would be no change in the general flow of goods. Which makes sense as it was hardly as though the Dutch were bringing in a bunch of stuff from the he Netherlands. They mostly acted as freighters, bringing things between Asian countries and using the profits to buy things to sent to Europe. Anyways, the Japanese would be well aware of what was going on in the world and wouldn't be running around like headless chickens. And they knew what guns were. Also, keep in mind that one month before Perry arrived the Russians landed in Nagasaki and showed off a steam engine, and a Japanese man attempted to make one within the year. Read up on him and you will be pleasantly surprised at how advanced science was in certain fields, and how the Dutch/Rangaku Learning was not an isolated field. Thoooough it did get a bit antsy for practitioners near the end.
https://en.wikipedia.org/wiki/Tanaka_Hisashige
https://en.wikipedia.org/wiki/Rangaku