local_ipaddress-0.1.3/.gitignore000064400000000000000000000000231353323257500150240ustar0000000000000000/target **/*.rs.bk local_ipaddress-0.1.3/Cargo.toml.orig000064400000000000000000000007661353324540700157370ustar0000000000000000[package] name = "local_ipaddress" version = "0.1.3" description = "Get your local IP address without panic" authors = ["egmkang wang "] edition = "2018" license = "MIT" readme = "README.md" repository = "https://github.com/egmkang/local_ipaddress" homepage = "https://github.com/egmkang/local_ipaddress" document = "https://docs.rs/local_ipaddress" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] local_ipaddress-0.1.3/Cargo.toml0000644000000015430000000000000122250ustar00# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g., crates.io) dependencies # # If you believe there's an error in this file please file an # issue against the rust-lang/cargo repository. If you're # editing this file be aware that the upstream Cargo.toml # will likely look very different (and much more reasonable) [package] edition = "2018" name = "local_ipaddress" version = "0.1.3" authors = ["egmkang wang "] description = "Get your local IP address without panic" homepage = "https://github.com/egmkang/local_ipaddress" readme = "README.md" license = "MIT" repository = "https://github.com/egmkang/local_ipaddress" [dependencies] local_ipaddress-0.1.3/LICENSE000064400000000000000000000021021353324302000140240ustar0000000000000000MIT License Copyright (c) 2019 egmkang wang Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. local_ipaddress-0.1.3/README.md000064400000000000000000000010411353324510000143000ustar0000000000000000# local_ipaddress Get your local ip address in Rust, using `UdpSocket` to get local ip address(not `network interface` or `ifconfig`), and won't `panic`. API Docs: [https://docs.rs/local_ipaddress](https://docs.rs/local_ipaddress) ### Usage Add this to your Cargo.toml: ``` [dependencies] local_ipaddress = "0.1.3" ``` ### Getting Started ```rust use local_ipaddress; fn main() { println!("{}", local_ipaddress::get().unwrap()); } ``` It works fine with both `Windows` and `Linux`. ### License MIT local_ipaddress-0.1.3/src/lib.rs000064400000000000000000000011431353324455500147440ustar0000000000000000//! A crate for get local ip address, //! without using `ifconfig` or scanning `network interface` use std::net::UdpSocket; /// get the local ip address, return an `Option`. when it fail, return `None`. pub fn get() -> Option { let socket = match UdpSocket::bind("0.0.0.0:0") { Ok(s) => s, Err(_) => return None, }; match socket.connect("8.8.8.8:80") { Ok(()) => (), Err(_) => return None, }; match socket.local_addr() { Ok(addr) => return Some(addr.ip().to_string()), Err(_) => return None, }; } local_ipaddress-0.1.3/src/main.rs000064400000000000000000000001421353323350200151060ustar0000000000000000extern crate local_ipaddress; fn main() { println!("{}", local_ipaddress::get().unwrap()); } local_ipaddress-0.1.3/.cargo_vcs_info.json0000644000000001120000000000000142160ustar00{ "git": { "sha1": "d64c66b9593537b3d2b1bff11dfac61891a7845a" } } local_ipaddress-0.1.3/Cargo.lock0000644000000002230000000000000121740ustar00# This file is automatically @generated by Cargo. # It is not intended for manual editing. [[package]] name = "local_ipaddress" version = "0.1.3"