Community detection is an important issue due to its wide use in designing network protocols such as data forwarding in Delay Tolerant Networks (DTN) and worm containment in Online Social Networks (OSN). However, most of the existing community detection algorithms focus on binary networks. Since most networks are weighted such as social networks, DTN or OSN, in this paper, we address the problems of community detection in weighted networks and exploit community for data forwarding in DTN and worm containment in OSN. We propose a novel community detection algorithm, and then introduce two metrics called intra-centrality and inter-centrality, to characterize nodes in communities. Based on these metrics, we propose an efficient data forwarding algorithm for DTN and an efficient worm containment strategy for OSN. Extensive trace-driven simulation results show that the data forwarding algorithm and the worm containment strategy significantly outperform existing works.