We analyze the problem of secure communication over a wiretap channel with an active adversary, in which the legitimate transmitter has the opportunity to sense and learn the adversary's actions. Specifically, the adversary has the ability to switch between two channels and to observe the corresponding output at every channel use; the encoder, however, has causal access to observations impacted by adversary's actions. We develop a joint learning/transmission scheme in which the legitimate users learn and adapt to the adversary's actions. For some channel models, we show that the achievable rates, which we define precisely, are arbitrarily close to those obtained with hindsight, had the transmitter known the actions ahead of time. This suggests that there is much to exploit and gain in physical-layer security by monitoring the environment.