<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="../assets/xml/rss.xsl" media="all"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Knowledge Base (Posts about ifconfig)</title><link>https://bgstack15.ddns.net/blog/</link><description></description><atom:link href="https://bgstack15.ddns.net/blog/categories/ifconfig.xml" rel="self" type="application/rss+xml"></atom:link><language>en</language><copyright>Contents © 2022 &lt;a href="mailto:bgstack15@gmail.com"&gt;bgstack15&lt;/a&gt; 
&lt;a rel="license" href="https://creativecommons.org/licenses/by-sa/4.0/"&gt;
&lt;img alt="Creative Commons License BY-SA"
style="border-width:0; margin-bottom:12px;"
src="https://bgstack15.ddns.net/.images/l_by-sa_4.0_88x31.png"&gt;&lt;/a&gt;</copyright><lastBuildDate>Fri, 18 Mar 2022 13:00:38 GMT</lastBuildDate><generator>Nikola (getnikola.com)</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>Fifconfig: my ifconfig.me ripoff</title><link>https://bgstack15.ddns.net/blog/posts/2022/03/18/fifconfig-my-ifconfig-me-ripoff/</link><dc:creator>bgstack15</dc:creator><description>&lt;p&gt;I used &lt;a href="http://ifconfig.me"&gt;ifconfig.me&lt;/a&gt; recently to show my public IP address, and I decided that I could write my own utility for that. I know that in Flask, the request object has all sorts of properties.&lt;/p&gt;
&lt;p&gt;So I wrote my own version, which I call Flask-ifconfig, or &lt;a href="https://bgstack15.ddns.net/fifconfig/"&gt;fifconfig&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;I made mine handle the 'Accept' header for json, html, xml, and text. You could also use a parameter, i.e., &lt;code&gt;?json&lt;/code&gt; to force that return type.&lt;/p&gt;
&lt;p&gt;You can check out the code at my &lt;a href="https://bgstack15.ddns.net/cgit/fifconfig"&gt;cgit site&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;README for fifconfig&lt;/h2&gt;
&lt;h3&gt;Upstream&lt;/h3&gt;
&lt;p&gt;&lt;a href="https://gitlab.com/bgstack15/fifconfig"&gt;gitlab&lt;/a&gt;
&lt;a href="https://bgstack15.ddns.net/cgit/fifconfig"&gt;author's git&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;Features&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Provide different output type based on &lt;code&gt;Accept&lt;/code&gt; header or url parameter. Options include:&lt;/li&gt;
&lt;li&gt;&lt;code&gt;application/json&lt;/code&gt; or &lt;code&gt;?json&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;text/html&lt;/code&gt; or &lt;code&gt;?html&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;application/xml&lt;/code&gt; or &lt;code&gt;?xml&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;text/plain&lt;/code&gt; or &lt;code&gt;?text&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Display IP address as viewed by the web server, or else the first entry of &lt;code&gt;HTTP_X_FORWARDED_FOR&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Using fifconfig&lt;/h3&gt;
&lt;p&gt;Visit the application.&lt;/p&gt;
&lt;pre class="code literal-block"&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;curl -L https://bgstack15.ddns.net/ifconfig/?json | jq
&lt;/code&gt;&lt;/pre&gt;

&lt;h4&gt;Installing&lt;/h4&gt;
&lt;p&gt;You can use flask for development, and uwsgi for production.&lt;/p&gt;
&lt;h4&gt;Instructions&lt;/h4&gt;
&lt;p&gt;Configure the application with these two files, based on the &lt;code&gt;.example&lt;/code&gt; files available in the source code:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;fifconfig.conf&lt;/li&gt;
&lt;li&gt;fifconfig.wsgi.ini&lt;/li&gt;
&lt;/ul&gt;
&lt;h5&gt;Development&lt;/h5&gt;
&lt;p&gt;Run server in development mode.&lt;/p&gt;
&lt;pre class="code literal-block"&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;FLASK_APP=fifconfig.py FLASK_DEBUG=True flask run --host='0.0.0.0'
&lt;/code&gt;&lt;/pre&gt;

&lt;h5&gt;Production&lt;/h5&gt;
&lt;p&gt;Run the server in a full wsgi environment for the cleanup timer to operate.&lt;/p&gt;
&lt;pre class="code literal-block"&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;./fifconfig.bin
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The html responses include links to the various single-field pages, unless you add a parameter &lt;code&gt;?nolinks&lt;/code&gt;. These links depend on any reverse-proxy servers adding themselves correctly to header &lt;code&gt;X-Forwarded-For&lt;/code&gt;.&lt;/p&gt;
&lt;h3&gt;Alternatives&lt;/h3&gt;
&lt;p&gt;This project was a ripoff of love of &lt;a href="http://ifconfig.me"&gt;http://ifconfig.me&lt;/a&gt;.&lt;/p&gt;
&lt;h3&gt;References&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href="https://tedboy.github.io/flask/generated/generated/flask.Request.html"&gt;flask.Request — Flask API&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://bgstack15.ddns.net/cgit/stackbin/tree/stackbin.py"&gt;my stackbin.py project&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://pypi.org/project/dicttoxml"&gt;dicttoxml - PyPI&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;</description><category>client</category><category>flask</category><category>http</category><category>ifconfig</category><category>python</category><guid>https://bgstack15.ddns.net/blog/posts/2022/03/18/fifconfig-my-ifconfig-me-ripoff/</guid><pubDate>Fri, 18 Mar 2022 12:58:44 GMT</pubDate></item></channel></rss>