Giter Club home page Giter Club logo

ipify-rs's Introduction

ipify-rs

Rust API & CLI for accessing the ipify.org HTTP API

Cirrus-CI Crates.io Docs GitHub release GitHub issues SemVer License dependency status

Licensed under the MIT.

  1. About
  2. API Usage
  3. Installation
  4. Example
  5. Documentation
  6. Contributing

About

This is my attempt at writing an API & CLI client for the IPIFY API (aka ipify.org). After looking at all the other crates, they are all flawed in some way (only IPv4, not really cargo compliant, etc.).

Supported Platforms

  • Unix (tested on FreeBSD, Linux and macOS)
  • Windows
    • cmd.exe
    • Powershell

API Usage

You first create an instance of Ipify with new() set the result you want (IPv4, IPv6) and its format (plain text, json). Result is a string.

  use ipify_rs::{Ipify,Op};
  
  let ip = Ipify::new().set(Op::IPv4).call();
  
  println!("My IP is {}", ip);

The four operations are specified as below:

  • OP::IPv4
  • OP::IPv6 (the default)
  • OP::IPv4J (json output)
  • Op::IPv6J (json output)

Minimalistic API

If you only care about the default (plain text, IPv6 query) and don't want to reuse anything later, then myip() is what you want:

use ipify_rs::myip;

fn main() {
    println!("{}", myip());
}

CLI utility

There is a CLI utility bundled with the API called ipify-cli.

    ipify-cli 0.4.0
    
    Ollivier Robert <[email protected]>
    
    Rust CLI for IPIFY API.
    
    USAGE:
        ipify-cli.exe [OPTIONS]
    
    OPTIONS:
        -4, --ipv4       Force getting IPv4
        -6, --ipv6       Force getting IPv6
        -h, --help       Print help information
        -J, --json       Request JSON output
        -q, --quiet      Quiet mode
        -V, --version    Display version and exit

You can see both API & CLI versions:

    $ ipify-cli -V
CLI ipify-cli/0.4.0 using API ipify-rs/0.5.0

Example

The file showall.rs inside examples show almost all parameters for the API. You can run it with:

    $ cargo run --example showall
    ...   
    INFO - Start
    INFO - Using default, minimal API
    IP=aaaa:bbbb:cccc:dddd:eeee:ffff:gggg:hhhh
    INFO - Using defaults (ipv6)
    IP=aaaa:bbbb:cccc:dddd:eeee:ffff:gggg:hhhh
    INFO - Using defaults, get json
    IP={"ip":"aaaa:bbbb:cccc:dddd:eeee:ffff:gggg:hhhh"}
    IP4="A.B.C.D"
    IP6="aaaa:bbbb:cccc:dddd:eeee:ffff:gggg:hhhh"

crates.io

You can use this package in your project by adding the following to your Cargo.toml:

[dependencies]
ipify-rs = "0.5.0"

then you can use it in your own crates.

Documentation

Full description of the API with examples is on docs.rs as usual: Ipify.

Contributing

Please see CONTRIBUTING.md for some simple rules.

I use Git Flow for this package so please use something similar or the usual github workflow.

  1. Fork it ( https://github.com/keltia/dmarc-rs/fork )
  2. Checkout the develop branch (git checkout develop)
  3. Create your feature branch (git checkout -b my-new-feature)
  4. Commit your changes (git commit -am 'Add some feature')
  5. Push to the branch (git push origin my-new-feature)
  6. Create a new Pull Request

ipify-rs's People

Contributors

keltia avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

kevinsumner

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.